persist user preference on what to do uploading existing files
Massimo Melina committed
May 12, 2024 at 11:05 UTC
1c9961f1e6585d58e2995282ffb3582910900068
2 files changed
+9
-8
frontend/src/state.ts
+3
@@ -35,7 +35,9 @@ export const state = proxy<typeof FRONTEND_OPTIONS & {
35
}
36
canChangePassword: boolean
37
uri: string
38
+ uploadOnExisting: 'skip' | 'overwrite' | 'rename'
39
}>({
40
+ uploadOnExisting: getHFS().dontOverwriteUploading ? 'rename' : 'skip',
41
uri: '',
42
canChangePassword: false,
43
props: {},
@@ -60,6 +62,7 @@ const SETTINGS_KEY = 'hfs_settings'
62
type StateKey = keyof typeof state
63
const SETTINGS_WITHOUT_GUI: StateKey[] = ['file_menu_on_link']
64
const SETTINGS_TO_STORE: StateKey[] = _.difference(typedKeys(FRONTEND_OPTIONS), SETTINGS_WITHOUT_GUI)
65
+ .concat(['uploadOnExisting']) // not adding this to FRONTEND_OPTIONS, as its possible values vary with the user permissions, but still makes sense to save on a single browser, supposedly for a single user
66
67
loadSettings()
68
for (const k of SETTINGS_TO_STORE)
frontend/src/upload.ts
+6
-8
@@ -33,7 +33,6 @@ export const uploadState = proxy<{
33
partial: number // relative to uploading file. This is how much we have done of the current queue.
34
speed: number
35
eta: number
36
- policyForExisting: 'skip' | 'overwrite' | 'rename'
36
}>({
37
eta: 0,
38
speed: 0,
@@ -46,7 +45,6 @@ export const uploadState = proxy<{
45
errors: [],
46
doneByte: 0,
47
done: [],
49
- policyForExisting: renameEnabled ? 'rename' : 'skip'
48
})
49
50
// keep track of speed
@@ -107,8 +105,8 @@ export function showUpload() {
105
}
106
107
function Content(){
110
- const { qs, paused, eta, speed, policyForExisting, adding } = useSnapshot(uploadState) as Readonly<typeof uploadState>
111
- const { props } = useSnapState()
108
+ const { qs, paused, eta, speed, adding } = useSnapshot(uploadState) as Readonly<typeof uploadState>
109
+ const { props, uploadOnExisting } = useSnapState()
110
const etaStr = useMemo(() => !eta ? '' : formatTime(eta*1000, 0, 2), [eta])
111
const inQ = _.sumBy(qs, q => q.entries.length) - (uploadState.uploading ? 1 : 0)
112
const queueStr = inQ && t('in_queue', { n: inQ }, "{n} in queue")
@@ -129,11 +127,11 @@ export function showUpload() {
127
onClick: () => pickFiles({ folder: true })
128
}, t`Pick folder`),
129
h('button', { className: 'create-folder', onClick: createFolder }, t`Create folder`),
132
- h(Select<typeof policyForExisting>, {
130
+ h(Select<typeof uploadOnExisting>, {
131
style: { width: 'unset' },
132
'aria-label': t`Overwrite policy`,
135
- value: policyForExisting || '',
136
- onChange: v => uploadState.policyForExisting = v,
133
+ value: uploadOnExisting || '',
134
+ onChange: v => state.uploadOnExisting = v,
135
options: onlyTruthy([
136
{ value: 'skip', label: t`Skip existing files` },
137
renameEnabled && { value: 'rename', label: t`Rename to avoid overwriting` },
@@ -340,7 +338,7 @@ async function startUpload(toUpload: ToUpload, to: string, resume=0) {
338
notificationChannel,
339
...resume && { resume: String(resume) },
340
...toUpload.comment && { comment: toUpload.comment },
343
- ...with_(uploadState.policyForExisting, x => x !== 'rename' && { existing: x }), // rename is the default
341
+ ...with_(state.uploadOnExisting, x => x !== 'rename' && { existing: x }), // rename is the default
342
}), true)
343
req.send(toUpload.file.slice(resume))
344