Commit 712a63a7 authored by Phil Hughes's avatar Phil Hughes

Merge branch '59514-uploading-images-base64' into 'master'

Resolve "Web IDE uploading images shows base64 string"

Closes #59514

See merge request gitlab-org/gitlab-ce!27471
parents cdada210 8e51207a
...@@ -57,6 +57,8 @@ export default { ...@@ -57,6 +57,8 @@ export default {
type: 'blob', type: 'blob',
content: result, content: result,
base64: !isText, base64: !isText,
binary: !isText,
rawPath: !isText ? target.result : '',
}); });
}, },
readFile(file) { readFile(file) {
......
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import flash from '~/flash'; import flash from '~/flash';
import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
...@@ -56,6 +57,10 @@ export default { ...@@ -56,6 +57,10 @@ export default {
active: this.file.viewMode === 'preview', active: this.file.viewMode === 'preview',
}; };
}, },
fileType() {
const info = viewerInformationForPath(this.file.path);
return (info && info.id) || '';
},
}, },
watch: { watch: {
file(newVal, oldVal) { file(newVal, oldVal) {
...@@ -258,6 +263,7 @@ export default { ...@@ -258,6 +263,7 @@ export default {
:path="file.rawPath || file.path" :path="file.rawPath || file.path"
:file-size="file.size" :file-size="file.size"
:project-path="file.projectId" :project-path="file.projectId"
:type="fileType"
/> />
<diff-viewer <diff-viewer
v-if="showDiffViewer" v-if="showDiffViewer"
......
...@@ -22,6 +22,8 @@ export const decorateFiles = ({ ...@@ -22,6 +22,8 @@ export const decorateFiles = ({
tempFile = false, tempFile = false,
content = '', content = '',
base64 = false, base64 = false,
binary = false,
rawPath = '',
}) => { }) => {
const treeList = []; const treeList = [];
const entries = {}; const entries = {};
...@@ -90,6 +92,8 @@ export const decorateFiles = ({ ...@@ -90,6 +92,8 @@ export const decorateFiles = ({
changed: tempFile, changed: tempFile,
content, content,
base64, base64,
binary,
rawPath,
previewMode: viewerInformationForPath(name), previewMode: viewerInformationForPath(name),
parentPath, parentPath,
}); });
......
...@@ -53,7 +53,7 @@ export const setResizingStatus = ({ commit }, resizing) => { ...@@ -53,7 +53,7 @@ export const setResizingStatus = ({ commit }, resizing) => {
export const createTempEntry = ( export const createTempEntry = (
{ state, commit, dispatch }, { state, commit, dispatch },
{ name, type, content = '', base64 = false }, { name, type, content = '', base64 = false, binary = false, rawPath = '' },
) => ) =>
new Promise(resolve => { new Promise(resolve => {
const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name; const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name;
...@@ -79,8 +79,10 @@ export const createTempEntry = ( ...@@ -79,8 +79,10 @@ export const createTempEntry = (
branchId: state.currentBranchId, branchId: state.currentBranchId,
type, type,
tempFile: true, tempFile: true,
base64,
content, content,
base64,
binary,
rawPath,
}); });
const { file, parentPath } = data; const { file, parentPath } = data;
......
...@@ -69,6 +69,8 @@ export const decorateData = entity => { ...@@ -69,6 +69,8 @@ export const decorateData = entity => {
changed = false, changed = false,
parentTreeUrl = '', parentTreeUrl = '',
base64 = false, base64 = false,
binary = false,
rawPath = '',
previewMode, previewMode,
file_lock, file_lock,
html, html,
...@@ -92,6 +94,8 @@ export const decorateData = entity => { ...@@ -92,6 +94,8 @@ export const decorateData = entity => {
renderError, renderError,
content, content,
base64, base64,
binary,
rawPath,
previewMode, previewMode,
file_lock, file_lock,
html, html,
......
<script> <script>
import { viewerInformationForPath } from './lib/viewer_utils';
import MarkdownViewer from './viewers/markdown_viewer.vue'; import MarkdownViewer from './viewers/markdown_viewer.vue';
import ImageViewer from './viewers/image_viewer.vue'; import ImageViewer from './viewers/image_viewer.vue';
import DownloadViewer from './viewers/download_viewer.vue'; import DownloadViewer from './viewers/download_viewer.vue';
...@@ -24,15 +23,18 @@ export default { ...@@ -24,15 +23,18 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
type: {
type: String,
required: false,
default: '',
},
}, },
computed: { computed: {
viewer() { viewer() {
if (!this.path) return null; if (!this.path) return null;
if (!this.type) return DownloadViewer;
const previewInfo = viewerInformationForPath(this.path); switch (this.type) {
if (!previewInfo) return DownloadViewer;
switch (previewInfo.id) {
case 'markdown': case 'markdown':
return MarkdownViewer; return MarkdownViewer;
case 'image': case 'image':
......
---
title: Show proper preview for uploaded images in Web IDE
merge_request: 27471
author:
type: fixed
...@@ -78,6 +78,8 @@ describe('new dropdown upload', () => { ...@@ -78,6 +78,8 @@ describe('new dropdown upload', () => {
type: 'blob', type: 'blob',
content: 'plain text', content: 'plain text',
base64: false, base64: false,
binary: false,
rawPath: '',
}); });
}); });
...@@ -89,6 +91,8 @@ describe('new dropdown upload', () => { ...@@ -89,6 +91,8 @@ describe('new dropdown upload', () => {
type: 'blob', type: 'blob',
content: binaryTarget.result.split('base64,')[1], content: binaryTarget.result.split('base64,')[1],
base64: true, base64: true,
binary: true,
rawPath: binaryTarget.result,
}); });
}); });
}); });
......
...@@ -4,6 +4,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -4,6 +4,7 @@ import axios from '~/lib/utils/axios_utils';
import contentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import contentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants'; import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants';
import '~/behaviors/markdown/render_gfm';
describe('ContentViewer', () => { describe('ContentViewer', () => {
let vm; let vm;
...@@ -29,6 +30,7 @@ describe('ContentViewer', () => { ...@@ -29,6 +30,7 @@ describe('ContentViewer', () => {
path: 'test.md', path: 'test.md',
content: '* Test', content: '* Test',
projectPath: 'testproject', projectPath: 'testproject',
type: 'markdown',
}); });
const previewContainer = vm.$el.querySelector('.md-previewer'); const previewContainer = vm.$el.querySelector('.md-previewer');
...@@ -44,6 +46,7 @@ describe('ContentViewer', () => { ...@@ -44,6 +46,7 @@ describe('ContentViewer', () => {
createComponent({ createComponent({
path: GREEN_BOX_IMAGE_URL, path: GREEN_BOX_IMAGE_URL,
fileSize: 1024, fileSize: 1024,
type: 'image',
}); });
setTimeout(() => { setTimeout(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment