fix: inconsistant path
This commit is contained in:
parent
a0e0114fdb
commit
ff712358cf
1 changed files with 13 additions and 7 deletions
|
|
@ -62,6 +62,10 @@ function constructUrl(path: string | string[], append = true) {
|
|||
: url
|
||||
}
|
||||
|
||||
function consistantPath(path: string | string[]) {
|
||||
return path.toString().split('/').filter(Boolean).join('/') + '/'
|
||||
}
|
||||
|
||||
const useStorage = defineStore('storageStore', () => {
|
||||
const loader = useLoader()
|
||||
const init = ref<boolean>(false)
|
||||
|
|
@ -131,7 +135,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
|
||||
const res = await api.get<(typeof folder.value)[string]>(constructUrl(arr))
|
||||
if (res.status === 200 && res.data && Array.isArray(res.data))
|
||||
folder.value[path] = res.data.sort((a, b) =>
|
||||
folder.value[consistantPath(path)] = res.data.sort((a, b) =>
|
||||
a.pathname.localeCompare(b.pathname),
|
||||
)
|
||||
}
|
||||
|
|
@ -145,7 +149,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
constructUrl(arr, false) + '/file',
|
||||
)
|
||||
if (res.status === 200 && res.data && Array.isArray(res.data))
|
||||
file.value[path] = res.data.sort((a, b) =>
|
||||
file.value[consistantPath(path)] = res.data.sort((a, b) =>
|
||||
a.pathname.localeCompare(b.pathname),
|
||||
)
|
||||
}
|
||||
|
|
@ -157,10 +161,12 @@ const useStorage = defineStore('storageStore', () => {
|
|||
// get all parent to the root structure
|
||||
// this will also triggher init structure as it get root structure
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const current = arr.slice(0, i - arr.length).join('/') + '/'
|
||||
const current = consistantPath(arr.slice(0, i - arr.length))
|
||||
if (!folder.value[current] || force) await getStorage(current)
|
||||
}
|
||||
|
||||
path = consistantPath(path)
|
||||
|
||||
// only get this path once, after that will get from socket.io-client instead
|
||||
if (!folder.value[path] || force) await getStorage(path)
|
||||
if (!file.value[path] || force) await getStorageFile(path)
|
||||
|
|
@ -173,7 +179,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
|
||||
async function gotoParent() {
|
||||
const arr = currentInfo.path.split('/').filter(Boolean)
|
||||
await goto([...arr.slice(0, -1), ''].join('/'))
|
||||
await goto(consistantPath(arr.slice(0, -1)))
|
||||
}
|
||||
|
||||
// socket.io zone
|
||||
|
|
@ -183,7 +189,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
socket.on('disconnect', () => console.info('Socket.io disconnected.'))
|
||||
socket.on('CreateFolder', (data: { pathname: string }) => {
|
||||
const arr = data.pathname.split('/').filter(Boolean)
|
||||
const path = [...arr.slice(0, -1), ''].join('/')
|
||||
const path = consistantPath(arr.slice(0, -1))
|
||||
|
||||
if (folder.value[path]) {
|
||||
folder.value[path].push({
|
||||
|
|
@ -201,7 +207,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
socket.on('EditFolder', (data: { from: string; to: string }) => {
|
||||
const src = data.from.split('/').filter(Boolean)
|
||||
const dst = data.to.split('/').filter(Boolean)
|
||||
const path = [...src.slice(0, -1), ''].join('/')
|
||||
const path = consistantPath(src.slice(0, -1))
|
||||
|
||||
if (folder.value[path]) {
|
||||
const val = folder.value[path].find((v) => v.pathname === data.from)
|
||||
|
|
@ -243,7 +249,7 @@ const useStorage = defineStore('storageStore', () => {
|
|||
}
|
||||
|
||||
const arr = data.pathname.split('/').filter(Boolean)
|
||||
const path = [...arr.slice(0, -1), ''].join('/')
|
||||
const path = consistantPath(arr.slice(0, -1))
|
||||
|
||||
if (folder.value[path]) {
|
||||
folder.value[path] = folder.value[path].filter(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue