Commit 166c3ea2 authored by Denys Mishunov's avatar Denys Mishunov

Stores 'binary' and 'rawPath' attr after upload

- When uploading a file, we need to flag binary files correspondingly
so that it gets propagated all the way to RepoEditor as it decides on
whether to show editor for this or that file or not (shouldHideEditor())

- rawPath needs to be propagate all the way to ContentViewer as well so
that uploaded images could be rendered as a base64 image right away
instead of raw base64 string
parent c8c8dd11
...@@ -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) {
......
...@@ -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,
......
...@@ -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,
}); });
}); });
}); });
......
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