upload: show specific errors
Massimo Melina committed
Jun 1, 2024 at 12:15 UTC
156f1b6abae003807877ea33269d670c459df83a
4 files changed
+14
-8
frontend/src/upload.ts
+7
-5
@@ -5,7 +5,7 @@ import { Btn, Flex, FlexV, iconBtn, Select } from './components'
5
import {
6
basename, closeDialog, formatBytes, formatPerc, hIcon, useIsMobile, newDialog, prefix, selectFiles, working,
7
HTTP_CONFLICT, HTTP_PAYLOAD_TOO_LARGE, formatSpeed, dirname, getHFS, onlyTruthy, with_, cpuSpeedIndex,
8
- buildUrlQueryString, randomId,
8
+ buildUrlQueryString, randomId, HTTP_MESSAGES,
9
} from './misc'
10
import _ from 'lodash'
11
import { INTERNAL_Snapshot, proxy, ref, snapshot, subscribe, useSnapshot } from 'valtio'
@@ -19,7 +19,7 @@ import { subscribeKey } from 'valtio/utils'
19
20
const renameEnabled = getHFS().dontOverwriteUploading
21
22
-interface ToUpload { file: File, comment?: string, name?: string, to?: string }
22
+interface ToUpload { file: File, comment?: string, name?: string, to?: string, error?: string }
23
export const uploadState = proxy<{
24
done: ToUpload[]
25
doneByte: number
@@ -378,11 +378,13 @@ async function startUpload(toUpload: ToUpload, to: string, resume=0) {
378
}
379
380
function error(status: number) {
381
- if (uploadState.errors.push(toUpload)) return
381
const ERRORS = {
382
[HTTP_PAYLOAD_TOO_LARGE]: t`file too large`,
383
+ [HTTP_CONFLICT]: t('upload_conflict', "already exists"),
384
}
385
- const specifier = (ERRORS as any)[status]
385
+ const specifier = (ERRORS as any)[status] || HTTP_MESSAGES[status]
386
+ toUpload.error = specifier
387
+ if (uploadState.errors.push(toUpload)) return
388
const msg = t('failed_upload', toUpload, "Couldn't upload {name}") + prefix(': ', specifier)
389
closeLast?.()
390
closeLast = alertDialog(msg, 'error').close
@@ -439,7 +441,7 @@ function UploadStatus({ snapshot, ...props }: { snapshot?: INTERNAL_Snapshot<typ
441
[msgErrors, errors]
442
] as const).map(([msg, list], i) =>
443
msg && h('div', { key: i }, msg, h('ul', {},
442
- list.map((x, i) => h('li', { key: i }, x.name || x.file.name)) )))
444
+ list.map((x, i) => h('li', { key: i }, x.name || x.file.name, prefix(' (', x.error, ')'))) )))
445
))
446
}
447
}
src/langs/hfs-lang-en.json
+2
-1
@@ -168,6 +168,7 @@
168
"clipboard": "Clipboard ({content})",
169
"to_clipboard_source_tooltip": "Go to the folder where the clipboard contents are located",
170
"more_items": "{n} more item(s)",
171
- "Show details": "Show details"
171
+ "Show details": "Show details",
172
+ "upload_conflict": "already exists"
173
}
174
}
src/langs/hfs-lang-fi.json
+3
-1
@@ -171,6 +171,8 @@
171
172
"clipboard": "Leikepöytä ({content})",
173
"to_clipboard_source_tooltip": "Mene kansioon jossa leikepöydän kohteet sijaitsevat",
174
- "more_items": "{n} lisää kohteita"
174
+ "more_items": "{n} lisää kohteita",
175
+ "Show details": "Näytä yksityiskohdat",
176
+ "upload_conflict": "on jo olemassa"
177
}
178
}
src/langs/hfs-lang-it.json
+2
-1
@@ -160,6 +160,7 @@
160
"clipboard": "Appunti ({content})",
161
"to_clipboard_source_tooltip": "Vai alla cartella d'origine dei file negli appunti",
162
"more_items": "{n,plural,one{Un altro elemento} other{# altri elementi}}",
163
- "Show details": "Mostra dettagli"
163
+ "Show details": "Mostra dettagli",
164
+ "upload_conflict": "esiste già"
165
}
166
}