Multiple file downloads via Filesystem API, and other tuning.

This commit is contained in:
Leo Vasanko
2023-11-04 19:50:05 +00:00
parent 40a45568c1
commit 41fbd3d122
10 changed files with 203 additions and 66 deletions

View File

@@ -3,7 +3,8 @@ import type {
DirEntry,
FileEntry,
FUID,
DirList
DirList,
SelectedItems,
} from '@/repositories/Document'
import { formatSize, formatUnixDate } from '@/utils'
import { defineStore } from 'pinia'
@@ -162,6 +163,50 @@ export const useDocumentStore = defineStore({
},
isUserLogged(): boolean {
return this.user.isLoggedIn
},
selectedFiles(): SelectedItems {
function traverseDir(data: DirEntry | FileEntry, path: string, relpath: string) {
if (!('dir' in data)) return
for (const [name, attr] of Object.entries(data.dir)) {
const fullname = path ? `${path}/${name}` : name
// Is this the file we are looking for? Ignore if nested within another selection.
let r = relpath
if (selected.has(attr.id) && !relpath) {
ret.selected.add(attr.id)
ret.rootdir[name] = attr
r = name
} else if (relpath) {
r = `${relpath}/${name}`
}
if (r) {
ret.entries[attr.id] = attr
ret.fullpath[attr.id] = fullname
ret.relpath[attr.id] = r
ret.ids.push(attr.id)
if (!("dir" in attr)) ret.url[attr.id] = `/files/${fullname}`
}
traverseDir(attr, fullname, r)
}
}
const selected = this.selected
const ret: SelectedItems = {
selected: new Set<FUID>(),
missing: new Set<FUID>(),
rootdir: {} as DirList,
entries: {} as Record<FUID, FileEntry | DirEntry>,
fullpath: {} as Record<FUID, string>,
relpath: {} as Record<FUID, string>,
url: {} as Record<FUID, string>,
ids: [] as FUID[]
}
traverseDir(this.root, '', '')
// What did we not select?
for (const id of selected) {
if (!ret.selected.has(id)) ret.missing.add(id)
}
// Sorted array of FUIDs for easy traversal
ret.ids.sort((a, b) => ret.relpath[a].localeCompare(ret.relpath[b] , undefined, {numeric: true, sensitivity: 'base'}))
return ret
}
}
})