admin/fs: comment #662

Massimo Melina committed Jul 7, 2024 at 01:27 UTC d741b617715674d8af850b468158851d4563f953
4 files changed +8 -6
admin/src/FileForm.ts
+4 -3
@@ -171,17 +171,18 @@ export default function FileForm({ file, addToBar, statusApi, accounts, saved }:
171 showTimestamps && { k: 'mtime', comp: DisplayField, sm: 6, lg: showSize && 4, label: "Modified", toField: formatTimestamp },
172 showAccept && { k: 'accept', label: "Accept on upload", placeholder: "anything", xl: showWebsite ? 4 : 12,
173 helperText: h(Link, { href: ACCEPT_LINK, target: '_blank' }, "Example: .zip") },
174 - showWebsite && { k: 'default', comp: BoolField, xl: true,
174 + showWebsite && { k: 'default', comp: BoolField, xl: showWebsite ? 8 : 12,
175 label: "Serve as web-page if index.html is found" + (inheritedDefault && values.default == null ? ' (inherited)' : ''),
176 value: values.default ?? inheritedDefault,
177 toField: Boolean, fromField: (v:boolean) => v && !inheritedDefault ? 'index.html' : v ? null : false,
178 helperText: md("...instead of showing list of files")
179 },
180 - isDir && { k: 'masks', multiline: true,
180 + { k: 'comment', multiline: true, xl: true },
181 + isDir && { k: 'masks', multiline: true, xl: 6,
182 toField: yaml.stringify, fromField: v => v ? yaml.parse(v) : undefined,
183 sx: { '& textarea': { fontFamily: 'monospace' } },
184 helperText: ["Special field, leave empty unless you know what you are doing. YAML syntax. ", wikiLink('Masks-field', "(examples)")]
184 - }
185 + },
186 ]
187 })
188
src/api.get_file_list.ts
+2 -2
@@ -45,7 +45,7 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
45 const can_archive = admin || hasPermission(fakeChild, 'can_archive', ctx)
46 const can_comment = can_upload && areCommentsEnabled()
47 const can_overwrite = can_upload && (can_delete || !dontOverwriteUploading.get())
48 - const comment = await getCommentFor(node.source)
48 + const comment = node.comment ?? await getCommentFor(node.source)
49 const props = { can_archive, can_upload, can_delete, can_overwrite, can_comment, comment, accept: node.accept }
50 ctx.state.browsing = uri.replace(/\/{2,}/g, '/')
51 updateConnectionForCtx(ctx)
@@ -126,7 +126,7 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
126 m: !st || Math.abs(+st.mtime - +st.ctime) < 1000 ? undefined : st.mtime,
127 s: isFolder ? undefined : st?.size,
128 p: (pr + pl + pd + pa) || undefined,
129 - comment: await getCommentFor(source),
129 + comment: node.comment ?? await getCommentFor(source),
130 web: await hasDefaultFile(node, ctx) ? true : undefined,
131 }
132 }
src/api.vfs.ts
+1 -1
@@ -23,7 +23,7 @@ async function urlToNodeOriginal(uri: string) {
23 return n?.isTemp ? n.original : n
24 }
25
26 -const ALLOWED_KEYS = ['name','source','masks','default','accept','rename','mime','url','target', ...PERM_KEYS]
26 +const ALLOWED_KEYS = ['name','source','masks','default','accept','rename','mime','url','target','comment', ...PERM_KEYS]
27
28 const apis: ApiHandlers = {
29
src/vfs.ts
+1
@@ -42,6 +42,7 @@ export interface VfsNodeStored extends VfsPerms {
42 rename?: Record<string, string>
43 masks?: Masks // express fields for descendants that are not in the tree
44 accept?: string
45 + comment?: string
46 }
47 export interface VfsNode extends VfsNodeStored { // include fields that are only filled at run-time
48 isTemp?: true // this node doesn't belong to the tree and was created by necessity