You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
fix: encoded file path on share
This commit is contained in:
@@ -1,23 +1,47 @@
|
||||
import { fetchJSON, removePrefix } from './utils'
|
||||
import { fetchURL, removePrefix } from './utils'
|
||||
import { baseURL } from '@/utils/constants'
|
||||
|
||||
export async function fetch(hash, password = "") {
|
||||
return fetchJSON(`/api/public/share/${hash}`, {
|
||||
export async function fetch (url, password = "") {
|
||||
url = removePrefix(url)
|
||||
|
||||
const res = await fetchURL(`/api/public/share${url}`, {
|
||||
headers: {'X-SHARE-PASSWORD': password},
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
let data = await res.json()
|
||||
data.url = `/share${url}`
|
||||
|
||||
if (data.isDir) {
|
||||
if (!data.url.endsWith('/')) data.url += '/'
|
||||
data.items = data.items.map((item, index) => {
|
||||
item.index = index
|
||||
item.url = `${data.url}${encodeURIComponent(item.name)}`
|
||||
|
||||
if (item.isDir) {
|
||||
item.url += '/'
|
||||
}
|
||||
|
||||
return item
|
||||
})
|
||||
}
|
||||
|
||||
return data
|
||||
} else {
|
||||
throw new Error(res.status)
|
||||
}
|
||||
}
|
||||
|
||||
export function download(format, hash, token, ...files) {
|
||||
let url = `${baseURL}/api/public/dl/${hash}`
|
||||
|
||||
const prefix = `/share/${hash}`
|
||||
if (files.length === 1) {
|
||||
url += removePrefix(files[0], prefix) + '?'
|
||||
url += encodeURIComponent(files[0]) + '?'
|
||||
} else {
|
||||
let arg = ''
|
||||
|
||||
for (let file of files) {
|
||||
arg += removePrefix(file, prefix) + ','
|
||||
arg += encodeURIComponent(file) + ','
|
||||
}
|
||||
|
||||
arg = arg.substring(0, arg.length - 1)
|
||||
|
||||
@@ -33,12 +33,8 @@ export async function fetchJSON (url, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
export function removePrefix (url, prefix) {
|
||||
if (url.startsWith('/files')) {
|
||||
url = url.slice(6)
|
||||
} else if (prefix) {
|
||||
url = url.replace(prefix, '')
|
||||
}
|
||||
export function removePrefix (url) {
|
||||
url = url.split('/').splice(2).join('/')
|
||||
|
||||
if (url === '') url = '/'
|
||||
if (url[0] !== '/') url = '/' + url
|
||||
|
||||
Reference in New Issue
Block a user