prevent inserting duplicates in upload queue

Massimo Melina committed Apr 21, 2023 at 10:24 UTC 9fb3692fb734ff1056c2ceaf9e2b8e025b0ca5d3
2 files changed +7 -7
frontend/src/upload.ts
+6 -6
@@ -220,14 +220,14 @@ export async function enqueue(files: File[]) {
220 if (_.remove(files, f => !simulateBrowserAccept(f)).length)
221 await alertDialog(t('upload_file_rejected', "Some files were not accepted"), 'warning')
222
223 - _.remove(files, f => { // avoid duplicates
224 - const match = path(f)
225 - return Boolean(_.find(files, x => x !== f && match === path(x)))
226 - })
223 + files = _.uniqBy(files, path)
224 if (!files.length) return
225 const to = location.pathname
229 - _.find(uploadState.qs, { to })?.files.push(...files.map(ref))
230 - || uploadState.qs.push({ to, files: files.map(ref) })
226 + const q = _.find(uploadState.qs, { to })
227 + if (!q)
228 + return uploadState.qs.push({ to, files: files.map(ref) })
229 + const missing = _.differenceBy(files, q.files, path)
230 + q.files.push(...missing.map(ref))
231 }
232
233 function simulateBrowserAccept(f: File) {
src/upload.ts
+1 -1
@@ -37,7 +37,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
37 return fail(HTTP_PAYLOAD_TOO_LARGE)
38 }
39 catch(e: any) {
40 - console.warn("can't check disk size", e.message || String(e))
40 + console.warn("can't check disk size:", e.message || String(e))
41 }
42 fs.mkdirSync(dir, { recursive: true })
43 const keepName = basename(fullPath).slice(-200)