upload: pause-button now affects also the current file
Massimo Melina committed
Aug 19, 2025 at 23:05 UTC
9d28eff2c3025ccf491407fac3ccf4aacd58977c
2 files changed
+17
-10
frontend/src/upload.ts
+13
-10
@@ -16,15 +16,13 @@ import { Link } from 'react-router-dom'
16
import { LinkClosingDialog } from './fileMenu'
17
import {
18
abortCurrentUpload, enqueueUpload, getFilePath, normalizeAccept, resetCounters, resetReloadOnClose,
19
- simulateBrowserAccept, ToUpload, uploadState
19
+ simulateBrowserAccept, startUpload, ToUpload, uploadState
20
} from './uploadQueue'
21
import i18n from './i18n'
22
const { t } = i18n
23
24
const renameEnabled = getHFS().dontOverwriteUploading
25
26
-let everPaused = false
27
-
26
export function showUpload() {
27
if (!uploadState.qs.length)
28
resetCounters()
@@ -130,12 +128,12 @@ export function showUpload() {
128
uploadState.qs = []
129
abortCurrentUpload(true)
130
}, { title: t`Clear` }),
133
- inQ > 0 && iconBtn(paused ? 'play' : 'pause', () => {
131
+ iconBtn(paused ? 'play' : 'pause', () => {
132
uploadState.paused = !uploadState.paused
135
- if (!everPaused) {
136
- everPaused = true
137
- alertDialog("Pause applies to the queue, but current file will still be uploaded")
138
- }
133
+ if (uploadState.paused)
134
+ abortCurrentUpload()
135
+ else if (uploadState.uploading)
136
+ startUpload(uploadState.uploading, uploadState.qs[0].to)
137
}),
138
),
139
qs.map((q,idx) =>
@@ -145,8 +143,13 @@ export function showUpload() {
143
entries: uploadState.qs[idx].entries,
144
actions: {
145
cancel: f => {
148
- if (f === uploadState.uploading)
149
- return abortCurrentUpload(true)
146
+ if (f === uploadState.uploading) {
147
+ if (!uploadState.paused)
148
+ return abortCurrentUpload(true)
149
+ f.error = t`Interrupted`
150
+ uploadState.skipped.push(f)
151
+ uploadState.uploading = undefined
152
+ }
153
const q = uploadState.qs[idx]
154
_.pull(q.entries, f)
155
if (!q.entries.length)
frontend/src/uploadQueue.ts
+4
@@ -74,6 +74,8 @@ setInterval(() => {
74
recentSpeedSamples.push(speed)
75
if (!doSample || recentSpeedSamples.length > 5) // max 5 samples, 10 seconds
76
recentSpeedSamples.shift()
77
+ if (uploadState.paused)
78
+ recentSpeedSamples.length = 0
79
uploadState.speed = _.mean(recentSpeedSamples)
80
uploadState.eta = left / uploadState.speed
81
}, 2_000)
@@ -108,6 +110,8 @@ export async function startUpload(toUpload: ToUpload, to: string, resume=0) {
110
req.onloadend = async () => { // loadend = fired for both success and error. Safari doesn't always fire this on disconnections, leaving readyState = 3. The problem is mitigated by the abort-when-stuck mechanism above.
111
try {
112
currentReq = undefined
113
+ if (uploadState.paused)
114
+ return stopLooping = true
115
strictResume = true // reset at each request
116
if (!userAborted && !req.status) { // we were disconnected, possibly with a status that we couldn't read, so we give it another chance without the body
117
/* Browsers are unreliable when it comes to read the status before the request is fully sent.