admin/fs: make possible to bind source to home

Massimo Melina committed Apr 9, 2022 at 18:19 UTC a02b8382313155a8b5530ad547fcf52c6963e1cf
3 files changed +9 -7
admin/src/FileCard.ts
+7 -5
@@ -6,7 +6,7 @@ import { Alert, Button, Card, CardContent, List, ListItem, ListItemText } from '
6 import { BoolField, DisplayField, Field, FieldProps, Form, MultiSelectField, SelectField } from './Form'
7 import { apiCall, useApiComp } from './api'
8 import { formatBytes, isEqualLax, modifiedSx, onlyTruthy } from './misc'
9 -import { reloadVfs, Who } from './VfsPage'
9 +import { reloadVfs, VfsNode, Who } from './VfsPage'
10 import md from './md'
11 import _ from 'lodash'
12
@@ -14,7 +14,7 @@ interface Account { username: string }
14
15 export default function FileCard() {
16 const { selectedFiles: files } = useSnapState()
17 - const file = files[0]
17 + const file = files[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way
18 if (!file)
19 return null
20 return h(Card, {},
@@ -27,7 +27,7 @@ export default function FileCard() {
27 ))
28 }
29
30 -function FileForm({ file }: { file: ReturnType<typeof useSnapState>['selectedFiles']['0'] }) {
30 +function FileForm({ file }: { file: VfsNode }) {
31 const { parent, children, isRoot, ...rest } = file
32 const [values, setValues] = useState(rest)
33 useEffect(() => {
@@ -79,7 +79,8 @@ function FileForm({ file }: { file: ReturnType<typeof useSnapState>['selectedFil
79 v !== file[k as keyof typeof values])
80 if (!props.masks)
81 props.masks = null // undefined cannot be serialized
82 - delete props.source
82 + if (!isRoot)
83 + delete props.source
84 await apiCall('set_vfs', {
85 uri: values.id,
86 props,
@@ -94,7 +95,8 @@ function FileForm({ file }: { file: ReturnType<typeof useSnapState>['selectedFil
95 k: 'name', validate: x => x>'' || `Required`,
96 helperText: source && "You can decide a name that's different from the one on your disk",
97 },
97 - hasSource && { k: 'source', comp: DisplayField, multiline: true },
98 + isRoot ? { k: 'source', helperText: "If you specify a folder here, its files will be listed in the home" }
99 + : (hasSource && { k: 'source', comp: DisplayField, multiline: true }),
100 { k: 'can_read', label:"Who can download", xl: showCanSee && 6, comp: WhoField, parent, accounts, inherit: inheritedPerms.can_read,
101 helperText: "Note: who can't download won't see it in the list"
102 },
server/src/api.vfs.ts
+2 -1
@@ -43,12 +43,13 @@ const apis: ApiHandlers = {
43 }
44 if (stats && Number(stats.mtime) === Number(stats.ctime))
45 delete stats.mtime
46 + const isRoot = node === vfs
47 return {
48 ...stats,
49 ...node,
50 website: dir && node.source && await stat(join(node.source, 'index.html')).then(() => true, () => undefined)
51 || undefined,
51 - name: getNodeName(node),
52 + name: isRoot ? undefined : getNodeName(node),
53 type: dir ? 'folder' : undefined,
54 children: node.children && await Promise.all(node.children.map(recur)),
55 }
todo.md
-1
@@ -6,7 +6,6 @@
6 - admin/fs: drag&drop to move items around
7 - admin/fs: support insert/delete key
8 - admin/fs: button "copy url to clipboard"
9 -- admin/fs: make possible to bind source to home
9 - admin/monitor: show some info on what folder is browsing
10 - if specified config is a folder, check for file config.yaml inside
11 - frontend: ok button to inputDialogs