fix: admin/fs: asking to delete root resulted in another element being removed
Massimo Melina committed
Feb 4, 2023 at 00:58 UTC
5d26efccad6ec1ca92c2a1ab098300d6fa6baf34
2 files changed
+9
-6
admin/src/VfsPage.ts
+5
-4
@@ -50,7 +50,7 @@ export default function VfsPage() {
50
: h(Fragment, {},
51
h(Flex, { alignItems: 'center' },
52
h(Typography, {variant: 'h6'}, selectedFiles.length + ' selected'),
53
- h(Button, { onClick: removeFiles, startIcon: h(Delete) }, "Remove"),
53
+ h(Button, { onClick: deleteFiles, startIcon: h(Delete) }, "Remove"),
54
),
55
h(List, { dense: true, disablePadding: true },
56
selectedFiles.map(f => h(ListItem, { key: f.id },
@@ -133,16 +133,17 @@ export function reloadVfs(pleaseSelect?: string[]) {
133
state.vfs = undefined
134
}
135
136
-export async function removeFiles() {
136
+export async function deleteFiles() {
137
const f = state.selectedFiles
138
if (!f.length) return
139
- if (!await confirmDialog(`Remove ${f.length} item(s)?`)) return
139
+ if (!await confirmDialog(`Delete ${f.length} item(s)?`)) return
140
try {
141
const uris = f.map(x => x.id)
142
+ _.pull(uris, '/')
143
const { errors } = await apiCall('del_vfs', { uris })
144
const urisThatFailed = uris.filter((uri, idx) => errors[idx])
145
if (urisThatFailed.length)
145
- return alertDialog("Following elements couldn't be removed: " + urisThatFailed.join(', '), 'error')
146
+ return alertDialog("Following elements couldn't be deleted: " + urisThatFailed.join(', '), 'error')
147
reloadVfs()
148
}
149
catch(e) {
src/api.vfs.ts
+4
-2
@@ -99,13 +99,15 @@ const apis: ApiHandlers = {
99
errors: await Promise.all(uris.map(async uri => {
100
if (typeof uri !== 'string')
101
return HTTP_BAD_REQUEST
102
+ if (uri === '/')
103
+ return HTTP_NOT_ACCEPTABLE
104
const node = await urlToNodeOriginal(uri)
105
if (!node)
106
return HTTP_NOT_FOUND
107
const parent = dirname(uri)
108
const parentNode = await urlToNodeOriginal(parent)
107
- if (!parentNode)
108
- return HTTP_NOT_ACCEPTABLE
109
+ if (!parentNode) // shouldn't happen
110
+ return HTTP_SERVER_ERROR
111
const { children } = parentNode
112
if (!children) // shouldn't happen
113
return HTTP_SERVER_ERROR