fix: encoded file path on share
This commit is contained in:
parent
e017a19985
commit
7955e0720b
|
@ -1,23 +1,47 @@
|
||||||
import { fetchJSON, removePrefix } from './utils'
|
import { fetchURL, removePrefix } from './utils'
|
||||||
import { baseURL } from '@/utils/constants'
|
import { baseURL } from '@/utils/constants'
|
||||||
|
|
||||||
export async function fetch(hash, password = "") {
|
export async function fetch (url, password = "") {
|
||||||
return fetchJSON(`/api/public/share/${hash}`, {
|
url = removePrefix(url)
|
||||||
|
|
||||||
|
const res = await fetchURL(`/api/public/share${url}`, {
|
||||||
headers: {'X-SHARE-PASSWORD': password},
|
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) {
|
export function download(format, hash, token, ...files) {
|
||||||
let url = `${baseURL}/api/public/dl/${hash}`
|
let url = `${baseURL}/api/public/dl/${hash}`
|
||||||
|
|
||||||
const prefix = `/share/${hash}`
|
|
||||||
if (files.length === 1) {
|
if (files.length === 1) {
|
||||||
url += removePrefix(files[0], prefix) + '?'
|
url += encodeURIComponent(files[0]) + '?'
|
||||||
} else {
|
} else {
|
||||||
let arg = ''
|
let arg = ''
|
||||||
|
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
arg += removePrefix(file, prefix) + ','
|
arg += encodeURIComponent(file) + ','
|
||||||
}
|
}
|
||||||
|
|
||||||
arg = arg.substring(0, arg.length - 1)
|
arg = arg.substring(0, arg.length - 1)
|
||||||
|
|
|
@ -33,12 +33,8 @@ export async function fetchJSON (url, opts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removePrefix (url, prefix) {
|
export function removePrefix (url) {
|
||||||
if (url.startsWith('/files')) {
|
url = url.split('/').splice(2).join('/')
|
||||||
url = url.slice(6)
|
|
||||||
} else if (prefix) {
|
|
||||||
url = url.replace(prefix, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url === '') url = '/'
|
if (url === '') url = '/'
|
||||||
if (url[0] !== '/') url = '/' + url
|
if (url[0] !== '/') url = '/' + url
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<a target="_blank" :href="link" class="button button--flat">{{ $t('buttons.download') }}</a>
|
<a target="_blank" :href="link" class="button button--flat">{{ $t('buttons.download') }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="share__box__element share__box__center">
|
<div class="share__box__element share__box__center">
|
||||||
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
|
<qrcode-vue :value="link" size="200" level="M"></qrcode-vue>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="req.isDir && req.items.length > 0" class="share__box share__box__items">
|
<div v-if="req.isDir && req.items.length > 0" class="share__box share__box__items">
|
||||||
|
@ -122,7 +122,6 @@ export default {
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
error: null,
|
error: null,
|
||||||
path: '',
|
|
||||||
showLimit: 500,
|
showLimit: 500,
|
||||||
password: '',
|
password: '',
|
||||||
attemptedPasswordLogin: false,
|
attemptedPasswordLogin: false,
|
||||||
|
@ -158,10 +157,9 @@ export default {
|
||||||
if (this.token !== ''){
|
if (this.token !== ''){
|
||||||
queryArg = `?token=${this.token}`
|
queryArg = `?token=${this.token}`
|
||||||
}
|
}
|
||||||
return `${baseURL}/api/public/dl/${this.hash}${this.path}${queryArg}`
|
|
||||||
},
|
const path = this.$route.path.split('/').splice(2).join('/')
|
||||||
fullLink: function () {
|
return `${baseURL}/api/public/dl/${path}${queryArg}`
|
||||||
return window.location.origin + this.link
|
|
||||||
},
|
},
|
||||||
humanSize: function () {
|
humanSize: function () {
|
||||||
if (this.req.isDir) {
|
if (this.req.isDir) {
|
||||||
|
@ -193,20 +191,19 @@ export default {
|
||||||
this.setLoading(true)
|
this.setLoading(true)
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
|
||||||
if (this.password !== ''){
|
if (this.password !== ''){
|
||||||
this.attemptedPasswordLogin = true
|
this.attemptedPasswordLogin = true
|
||||||
}
|
}
|
||||||
let file = await api.fetch(encodeURIComponent(this.$route.params.pathMatch), this.password)
|
|
||||||
this.path = file.path
|
let url = this.$route.path
|
||||||
if (this.path.endsWith('/')) this.path = this.path.slice(0, -1)
|
if (url === '') url = '/'
|
||||||
|
if (url[0] !== '/') url = '/' + url
|
||||||
|
|
||||||
|
try {
|
||||||
|
let file = await api.fetch(url, this.password)
|
||||||
|
|
||||||
this.token = file.token || ''
|
this.token = file.token || ''
|
||||||
if (file.isDir) file.items = file.items.map((item, index) => {
|
|
||||||
item.index = index
|
|
||||||
item.url = `/share/${this.hash}${this.path}/${encodeURIComponent(item.name)}`
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
this.updateRequest(file)
|
this.updateRequest(file)
|
||||||
this.setLoading(false)
|
this.setLoading(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -228,7 +225,7 @@ export default {
|
||||||
},
|
},
|
||||||
download () {
|
download () {
|
||||||
if (this.selectedCount === 1 && !this.req.items[this.selected[0]].isDir) {
|
if (this.selectedCount === 1 && !this.req.items[this.selected[0]].isDir) {
|
||||||
api.download(null, this.hash, this.token, this.req.items[this.selected[0]].url)
|
api.download(null, this.hash, this.token, this.req.items[this.selected[0]].path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +237,7 @@ export default {
|
||||||
let files = []
|
let files = []
|
||||||
|
|
||||||
for (let i of this.selected) {
|
for (let i of this.selected) {
|
||||||
files.push(this.req.items[i].url)
|
files.push(this.req.items[i].path)
|
||||||
}
|
}
|
||||||
|
|
||||||
api.download(format, this.hash, this.token, ...files)
|
api.download(format, this.hash, this.token, ...files)
|
||||||
|
|
Loading…
Reference in New Issue