Rename FUID field to key everywhere.
This commit is contained in:
parent
9d3d27faf3
commit
14f7253ece
|
@ -30,13 +30,13 @@ export type errorEvent = {
|
|||
// Raw types the backend /api/watch sends us
|
||||
|
||||
export type FileEntry = {
|
||||
id: FUID
|
||||
key: FUID
|
||||
size: number
|
||||
mtime: number
|
||||
}
|
||||
|
||||
export type DirEntry = {
|
||||
id: FUID
|
||||
key: FUID
|
||||
size: number
|
||||
mtime: number
|
||||
dir: DirList
|
||||
|
@ -47,7 +47,7 @@ export type DirList = Record<string, FileEntry | DirEntry>
|
|||
export type UpdateEntry = {
|
||||
name: string
|
||||
deleted?: boolean
|
||||
id?: FUID
|
||||
key?: FUID
|
||||
size?: number
|
||||
mtime?: number
|
||||
dir?: DirList
|
||||
|
@ -127,7 +127,7 @@ export class DocumentHandler {
|
|||
// @ts-ignore
|
||||
node = node.dir[elem.name] ||= {}
|
||||
}
|
||||
if (elem.id !== undefined) node.id = elem.id
|
||||
if (elem.key !== undefined) node.key = elem.key
|
||||
if (elem.size !== undefined) node.size = elem.size
|
||||
if (elem.mtime !== undefined) node.mtime = elem.mtime
|
||||
if (elem.dir !== undefined) node.dir = elem.dir
|
||||
|
|
|
@ -60,10 +60,10 @@ export const useDocumentStore = defineStore({
|
|||
// Transform data
|
||||
const dataMapped = []
|
||||
for (const [name, attr] of Object.entries(matched)) {
|
||||
const { id, size, mtime } = attr
|
||||
const { key, size, mtime } = attr
|
||||
const element: Document = {
|
||||
name,
|
||||
key: id,
|
||||
key,
|
||||
size,
|
||||
sizedisp: formatSize(size),
|
||||
mtime,
|
||||
|
@ -182,21 +182,22 @@ export const useDocumentStore = defineStore({
|
|||
if (!('dir' in data)) return
|
||||
for (const [name, attr] of Object.entries(data.dir)) {
|
||||
const fullname = path ? `${path}/${name}` : name
|
||||
const key = attr.key
|
||||
// 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)
|
||||
if (selected.has(key) && !relpath) {
|
||||
ret.selected.add(key)
|
||||
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}`
|
||||
ret.entries[key] = attr
|
||||
ret.fullpath[key] = fullname
|
||||
ret.relpath[key] = r
|
||||
ret.ids.push(key)
|
||||
if (!('dir' in attr)) ret.url[key] = `/files/${fullname}`
|
||||
}
|
||||
traverseDir(attr, fullname, r)
|
||||
}
|
||||
|
|
|
@ -110,13 +110,13 @@ class ErrorMsg(msgspec.Struct):
|
|||
|
||||
|
||||
class FileEntry(msgspec.Struct):
|
||||
id: str
|
||||
key: str
|
||||
size: int
|
||||
mtime: int
|
||||
|
||||
|
||||
class DirEntry(msgspec.Struct):
|
||||
id: str
|
||||
key: str
|
||||
size: int
|
||||
mtime: int
|
||||
dir: DirList
|
||||
|
@ -146,7 +146,7 @@ class UpdateEntry(msgspec.Struct, omit_defaults=True):
|
|||
|
||||
name: str = ""
|
||||
deleted: bool = False
|
||||
id: str | None = None
|
||||
key: str | None = None
|
||||
size: int | None = None
|
||||
mtime: int | None = None
|
||||
dir: DirList | None = None
|
||||
|
|
|
@ -90,7 +90,9 @@ def format_tree():
|
|||
return msgspec.json.encode(
|
||||
{
|
||||
"update": [
|
||||
UpdateEntry(id=root.id, size=root.size, mtime=root.mtime, dir=root.dir),
|
||||
UpdateEntry(
|
||||
key=root.key, size=root.size, mtime=root.mtime, dir=root.dir
|
||||
),
|
||||
],
|
||||
},
|
||||
).decode()
|
||||
|
@ -99,10 +101,11 @@ def format_tree():
|
|||
def walk(path: Path) -> DirEntry | FileEntry | None:
|
||||
try:
|
||||
s = path.stat()
|
||||
id_ = fuid(s)
|
||||
key = fuid(s)
|
||||
assert key, repr(key)
|
||||
mtime = int(s.st_mtime)
|
||||
if path.is_file():
|
||||
return FileEntry(id_, s.st_size, mtime)
|
||||
return FileEntry(key, s.st_size, mtime)
|
||||
|
||||
tree = {
|
||||
p.name: v
|
||||
|
@ -115,7 +118,7 @@ def walk(path: Path) -> DirEntry | FileEntry | None:
|
|||
mtime = max(mtime, *(v.mtime for v in tree.values()))
|
||||
else:
|
||||
size = 0
|
||||
return DirEntry(id_, size, mtime, tree)
|
||||
return DirEntry(key, size, mtime, tree)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
except OSError as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user