From babd7783afe85b790e1c558375d7b5013b2d366f Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Tue, 29 Sep 2020 14:04:03 +0000 Subject: [PATCH 1/4] fix: file upload path encoding --- frontend/src/utils/upload.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/frontend/src/utils/upload.js b/frontend/src/utils/upload.js index 54b5669e..a43f5787 100644 --- a/frontend/src/utils/upload.js +++ b/frontend/src/utils/upload.js @@ -96,31 +96,25 @@ export function scanFiles(dt) { }) } -export function handleFiles(files, path, overwrite = false) { +export function handleFiles(files, base, overwrite = false) { for (let i = 0; i < files.length; i++) { + let id = store.state.upload.id + let path = base let file = files[i] - let filename = (file.fullPath !== undefined) ? file.fullPath : file.name - let filenameEncoded = url.encodeRFC5987ValueChars(filename) - - let id = store.state.upload.id - - let itemPath = path + filenameEncoded + if (file.fullPath !== undefined) { + path += url.encodePath(file.fullPath) + } else { + path += url.encodeRFC5987ValueChars(file.name) + } if (file.isDir) { - itemPath = path - let folders = file.fullPath.split("/") - - for (let i = 0; i < folders.length; i++) { - let folder = folders[i] - let folderEncoded = encodeURIComponent(folder) - itemPath += folderEncoded + "/" - } + path += '/' } const item = { id, - path: itemPath, + path, file, overwrite } From 26d62e411716a5eb9a5a703e47484cfb3fbf3bd0 Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Tue, 29 Sep 2020 14:04:43 +0000 Subject: [PATCH 2/4] fix: search results absolute url --- frontend/src/api/search.js | 28 +++++++++++++++++++++++----- frontend/src/components/Search.vue | 8 ++++++-- search/search.go | 4 +++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/frontend/src/api/search.js b/frontend/src/api/search.js index ec35e6e3..9dfaf8ee 100644 --- a/frontend/src/api/search.js +++ b/frontend/src/api/search.js @@ -1,8 +1,26 @@ -import { fetchJSON, removePrefix } from './utils' +import { fetchURL, removePrefix } from './utils' +import url from '../utils/url' -export default async function search (url, query) { - url = removePrefix(url) +export default async function search (base, query) { + base = removePrefix(base) query = encodeURIComponent(query) - return fetchJSON(`/api/search${url}?query=${query}`, {}) -} + if (!base.endsWith('/')) { + base += '/' + } + + let res = await fetchURL(`/api/search${base}?query=${query}`, {}) + + if (res.status === 200) { + let data = await res.json() + + data = data.map((item) => { + item.url = `/files${base}` + url.encodePath(item.path) + return item + }) + + return data + } else { + throw Error(res.status) + } +} \ No newline at end of file diff --git a/frontend/src/components/Search.vue b/frontend/src/components/Search.vue index 0762f05e..c723d6b1 100644 --- a/frontend/src/components/Search.vue +++ b/frontend/src/components/Search.vue @@ -49,7 +49,7 @@