Frontend created and rewritten a few times, with some backend fixes #1

Merged
leo merged 110 commits from plaintable into main 2023-11-08 20:38:40 +00:00
4 changed files with 24 additions and 20 deletions
Showing only changes of commit 14f7253ece - Show all commits

View File

@ -30,13 +30,13 @@ export type errorEvent = {
// Raw types the backend /api/watch sends us // Raw types the backend /api/watch sends us
export type FileEntry = { export type FileEntry = {
id: FUID key: FUID
size: number size: number
mtime: number mtime: number
} }
export type DirEntry = { export type DirEntry = {
id: FUID key: FUID
size: number size: number
mtime: number mtime: number
dir: DirList dir: DirList
@ -47,7 +47,7 @@ export type DirList = Record<string, FileEntry | DirEntry>
export type UpdateEntry = { export type UpdateEntry = {
name: string name: string
deleted?: boolean deleted?: boolean
id?: FUID key?: FUID
size?: number size?: number
mtime?: number mtime?: number
dir?: DirList dir?: DirList
@ -127,7 +127,7 @@ export class DocumentHandler {
// @ts-ignore // @ts-ignore
node = node.dir[elem.name] ||= {} 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.size !== undefined) node.size = elem.size
if (elem.mtime !== undefined) node.mtime = elem.mtime if (elem.mtime !== undefined) node.mtime = elem.mtime
if (elem.dir !== undefined) node.dir = elem.dir if (elem.dir !== undefined) node.dir = elem.dir

View File

@ -60,10 +60,10 @@ export const useDocumentStore = defineStore({
// Transform data // Transform data
const dataMapped = [] const dataMapped = []
for (const [name, attr] of Object.entries(matched)) { for (const [name, attr] of Object.entries(matched)) {
const { id, size, mtime } = attr const { key, size, mtime } = attr
const element: Document = { const element: Document = {
name, name,
key: id, key,
size, size,
sizedisp: formatSize(size), sizedisp: formatSize(size),
mtime, mtime,
@ -182,21 +182,22 @@ export const useDocumentStore = defineStore({
if (!('dir' in data)) return if (!('dir' in data)) return
for (const [name, attr] of Object.entries(data.dir)) { for (const [name, attr] of Object.entries(data.dir)) {
const fullname = path ? `${path}/${name}` : name const fullname = path ? `${path}/${name}` : name
const key = attr.key
// Is this the file we are looking for? Ignore if nested within another selection. // Is this the file we are looking for? Ignore if nested within another selection.
let r = relpath let r = relpath
if (selected.has(attr.id) && !relpath) { if (selected.has(key) && !relpath) {
ret.selected.add(attr.id) ret.selected.add(key)
ret.rootdir[name] = attr ret.rootdir[name] = attr
r = name r = name
} else if (relpath) { } else if (relpath) {
r = `${relpath}/${name}` r = `${relpath}/${name}`
} }
if (r) { if (r) {
ret.entries[attr.id] = attr ret.entries[key] = attr
ret.fullpath[attr.id] = fullname ret.fullpath[key] = fullname
ret.relpath[attr.id] = r ret.relpath[key] = r
ret.ids.push(attr.id) ret.ids.push(key)
if (!('dir' in attr)) ret.url[attr.id] = `/files/${fullname}` if (!('dir' in attr)) ret.url[key] = `/files/${fullname}`
} }
traverseDir(attr, fullname, r) traverseDir(attr, fullname, r)
} }

View File

@ -110,13 +110,13 @@ class ErrorMsg(msgspec.Struct):
class FileEntry(msgspec.Struct): class FileEntry(msgspec.Struct):
id: str key: str
size: int size: int
mtime: int mtime: int
class DirEntry(msgspec.Struct): class DirEntry(msgspec.Struct):
id: str key: str
size: int size: int
mtime: int mtime: int
dir: DirList dir: DirList
@ -146,7 +146,7 @@ class UpdateEntry(msgspec.Struct, omit_defaults=True):
name: str = "" name: str = ""
deleted: bool = False deleted: bool = False
id: str | None = None key: str | None = None
size: int | None = None size: int | None = None
mtime: int | None = None mtime: int | None = None
dir: DirList | None = None dir: DirList | None = None

View File

@ -90,7 +90,9 @@ def format_tree():
return msgspec.json.encode( return msgspec.json.encode(
{ {
"update": [ "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() ).decode()
@ -99,10 +101,11 @@ def format_tree():
def walk(path: Path) -> DirEntry | FileEntry | None: def walk(path: Path) -> DirEntry | FileEntry | None:
try: try:
s = path.stat() s = path.stat()
id_ = fuid(s) key = fuid(s)
assert key, repr(key)
mtime = int(s.st_mtime) mtime = int(s.st_mtime)
if path.is_file(): if path.is_file():
return FileEntry(id_, s.st_size, mtime) return FileEntry(key, s.st_size, mtime)
tree = { tree = {
p.name: v p.name: v
@ -115,7 +118,7 @@ def walk(path: Path) -> DirEntry | FileEntry | None:
mtime = max(mtime, *(v.mtime for v in tree.values())) mtime = max(mtime, *(v.mtime for v in tree.values()))
else: else:
size = 0 size = 0
return DirEntry(id_, size, mtime, tree) return DirEntry(key, size, mtime, tree)
except FileNotFoundError: except FileNotFoundError:
return None return None
except OSError as e: except OSError as e: