@samitouri / QOSami-HFS / commits / 8d783687

fix: admin/fs: error trying to delete at the same time an item and a sub-item

Massimo Melina committed Apr 6, 2025 at 19:01 UTC 8d7836871d88c8c9e04fa0d1588f159ebc845d4a
2 files changed +4 -2
admin/src/VfsPage.ts
+3 -1
@@ -175,7 +175,9 @@ export async function deleteFiles() {
175 if (!f.length) return
176 if (!await confirmDialog(`Delete ${f.length} item(s)?`)) return
177 try {
178 - const uris = f.map(x => x.id)
178 + const uris = f.map(x => x.id).sort()
179 + _.remove(uris, (x, i) => i // exclude first, but remove descendants as they are both redundant and would cause errors
180 + && _.findLastIndex(uris, y => x.startsWith(y), i - 1) !== -1) // search backward among previous elements, as they array is sorted
181 _.pull(uris, '/')
182 const { errors } = await apiCall('del_vfs', { uris })
183 const urisThatFailed = uris.filter((uri, idx) => errors[idx])
frontend/src/show.ts
+1 -1
@@ -167,7 +167,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false, startShuffle=fal
167 }),
168 ),
169 iconBtn('menu', ev => openFileMenu(cur, ev, [
170 - 'open','delete',
170 + 'open', 'delete',
171 { id: 'zoom', icon: 'zoom', label: t`Switch zoom mode`, onClick: switchZoomMode },
172 { id: 'fullscreen', icon: 'fullscreen', label: t`Full screen`, onClick: toggleFullScreen },
173 { id: 'shuffle', icon: 'shuffle', label: t`Shuffle`, toggled: Boolean(shuffle), onClick: () => toggleShuffle() },