|
@@ -91,10 +91,25 @@ export default class MiniXHRUpload {
|
|
|
|
|
|
uploadFile (id, current, total) {
|
|
|
const file = this.uppy.getFile(id)
|
|
|
+ this.uppy.log(`uploading ${current} of ${total}`)
|
|
|
+
|
|
|
if (file.error) {
|
|
|
throw new Error(file.error)
|
|
|
} else if (file.isRemote) {
|
|
|
- return this.#uploadRemoteFile(file, current, total)
|
|
|
+ const controller = new AbortController()
|
|
|
+
|
|
|
+ const removedHandler = (removedFile) => {
|
|
|
+ if (removedFile.id === file.id) controller.abort()
|
|
|
+ }
|
|
|
+ this.uppy.on('file-removed', removedHandler)
|
|
|
+
|
|
|
+ const uploadPromise = this.#uploadRemoteFile(file, { signal: controller.signal })
|
|
|
+
|
|
|
+ this.requests.wrapSyncFunction(() => {
|
|
|
+ this.uppy.off('file-removed', removedHandler)
|
|
|
+ }, { priority: -1 })()
|
|
|
+
|
|
|
+ return uploadPromise
|
|
|
}
|
|
|
return this.#uploadLocalFile(file, current, total)
|
|
|
}
|
|
@@ -115,10 +130,9 @@ export default class MiniXHRUpload {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- #uploadLocalFile (file, current, total) {
|
|
|
+ #uploadLocalFile (file) {
|
|
|
const opts = this.#getOptions(file)
|
|
|
|
|
|
- this.uppy.log(`uploading ${current} of ${total}`)
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
@@ -281,22 +295,26 @@ export default class MiniXHRUpload {
|
|
|
|
|
|
|
|
|
|
|
|
- async #uploadRemoteFile (file) {
|
|
|
+ async #uploadRemoteFile (file, options) {
|
|
|
|
|
|
try {
|
|
|
if (file.serverToken) {
|
|
|
return await this.connectToServerSocket(file)
|
|
|
}
|
|
|
- const serverToken = await this.#queueRequestSocketToken(file)
|
|
|
+ const serverToken = await this.#queueRequestSocketToken(file, options).abortOn(options?.signal)
|
|
|
|
|
|
if (!this.uppy.getState().files[file.id]) return undefined
|
|
|
|
|
|
this.uppy.setFileState(file.id, { serverToken })
|
|
|
return await this.connectToServerSocket(this.uppy.getFile(file.id))
|
|
|
} catch (err) {
|
|
|
- this.uppy.setFileState(file.id, { serverToken: undefined })
|
|
|
- this.uppy.emit('upload-error', file, err)
|
|
|
- throw err
|
|
|
+ if (err?.cause?.name !== 'AbortError') {
|
|
|
+ this.uppy.setFileState(file.id, { serverToken: undefined })
|
|
|
+ this.uppy.emit('upload-error', file, err)
|
|
|
+ throw err
|
|
|
+ }
|
|
|
+
|
|
|
+ return undefined
|
|
|
}
|
|
|
}
|
|
|
|