|
@@ -86,9 +86,12 @@ class HTTPCommunicationQueue {
|
|
|
|
|
|
#uploadPartBytes
|
|
#uploadPartBytes
|
|
|
|
|
|
- constructor (requests, options, setS3MultipartState) {
|
|
|
|
|
|
+ #getFile
|
|
|
|
+
|
|
|
|
+ constructor (requests, options, setS3MultipartState, getFile) {
|
|
this.#requests = requests
|
|
this.#requests = requests
|
|
this.#setS3MultipartState = setS3MultipartState
|
|
this.#setS3MultipartState = setS3MultipartState
|
|
|
|
+ this.#getFile = getFile
|
|
this.setOptions(options)
|
|
this.setOptions(options)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,7 +200,7 @@ class HTTPCommunicationQueue {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- const promise = this.#createMultipartUpload(file, signal)
|
|
|
|
|
|
+ const promise = this.#createMultipartUpload(this.#getFile(file), signal)
|
|
|
|
|
|
const abortPromise = () => {
|
|
const abortPromise = () => {
|
|
promise.abort(signal.reason)
|
|
promise.abort(signal.reason)
|
|
@@ -235,7 +238,7 @@ class HTTPCommunicationQueue {
|
|
// If the cached result rejects, there's nothing to abort.
|
|
// If the cached result rejects, there's nothing to abort.
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- await this.#abortMultipartUpload(file, awaitedResult)
|
|
|
|
|
|
+ await this.#abortMultipartUpload(this.#getFile(file), awaitedResult)
|
|
}
|
|
}
|
|
|
|
|
|
async #nonMultipartUpload (file, chunk, signal) {
|
|
async #nonMultipartUpload (file, chunk, signal) {
|
|
@@ -244,7 +247,7 @@ class HTTPCommunicationQueue {
|
|
url,
|
|
url,
|
|
fields,
|
|
fields,
|
|
headers,
|
|
headers,
|
|
- } = await this.#getUploadParameters(file, { signal }).abortOn(signal)
|
|
|
|
|
|
+ } = await this.#getUploadParameters(this.#getFile(file), { signal }).abortOn(signal)
|
|
|
|
|
|
let body
|
|
let body
|
|
const data = chunk.getData()
|
|
const data = chunk.getData()
|
|
@@ -285,7 +288,10 @@ class HTTPCommunicationQueue {
|
|
try {
|
|
try {
|
|
const parts = await Promise.all(chunks.map((chunk, i) => this.uploadChunk(file, i + 1, chunk, signal)))
|
|
const parts = await Promise.all(chunks.map((chunk, i) => this.uploadChunk(file, i + 1, chunk, signal)))
|
|
throwIfAborted(signal)
|
|
throwIfAborted(signal)
|
|
- return await this.#sendCompletionRequest(file, { key, uploadId, parts, signal }).abortOn(signal)
|
|
|
|
|
|
+ return await this.#sendCompletionRequest(
|
|
|
|
+ this.#getFile(file),
|
|
|
|
+ { key, uploadId, parts, signal },
|
|
|
|
+ ).abortOn(signal)
|
|
} catch (err) {
|
|
} catch (err) {
|
|
if (err?.cause !== pausingUploadReason && err?.name !== 'AbortError') {
|
|
if (err?.cause !== pausingUploadReason && err?.name !== 'AbortError') {
|
|
// We purposefully don't wait for the promise and ignore its status,
|
|
// We purposefully don't wait for the promise and ignore its status,
|
|
@@ -308,7 +314,10 @@ class HTTPCommunicationQueue {
|
|
}
|
|
}
|
|
const { uploadId, key } = await this.getUploadId(file, signal)
|
|
const { uploadId, key } = await this.getUploadId(file, signal)
|
|
throwIfAborted(signal)
|
|
throwIfAborted(signal)
|
|
- const alreadyUploadedParts = await this.#listParts(file, { uploadId, key, signal }).abortOn(signal)
|
|
|
|
|
|
+ const alreadyUploadedParts = await this.#listParts(
|
|
|
|
+ this.#getFile(file),
|
|
|
|
+ { uploadId, key, signal },
|
|
|
|
+ ).abortOn(signal)
|
|
throwIfAborted(signal)
|
|
throwIfAborted(signal)
|
|
const parts = await Promise.all(
|
|
const parts = await Promise.all(
|
|
chunks
|
|
chunks
|
|
@@ -324,7 +333,10 @@ class HTTPCommunicationQueue {
|
|
}),
|
|
}),
|
|
)
|
|
)
|
|
throwIfAborted(signal)
|
|
throwIfAborted(signal)
|
|
- return this.#sendCompletionRequest(file, { key, uploadId, parts, signal }).abortOn(signal)
|
|
|
|
|
|
+ return this.#sendCompletionRequest(
|
|
|
|
+ this.#getFile(file),
|
|
|
|
+ { key, uploadId, parts, signal },
|
|
|
|
+ ).abortOn(signal)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -343,7 +355,7 @@ class HTTPCommunicationQueue {
|
|
const chunkData = chunk.getData()
|
|
const chunkData = chunk.getData()
|
|
const { onProgress, onComplete } = chunk
|
|
const { onProgress, onComplete } = chunk
|
|
|
|
|
|
- const signature = await this.#fetchSignature(file, {
|
|
|
|
|
|
+ const signature = await this.#fetchSignature(this.#getFile(file), {
|
|
uploadId, key, partNumber, body: chunkData, signal,
|
|
uploadId, key, partNumber, body: chunkData, signal,
|
|
}).abortOn(signal)
|
|
}).abortOn(signal)
|
|
|
|
|
|
@@ -413,7 +425,12 @@ export default class AwsS3Multipart extends UploaderPlugin {
|
|
* @type {RateLimitedQueue}
|
|
* @type {RateLimitedQueue}
|
|
*/
|
|
*/
|
|
this.requests = this.opts.rateLimitedQueue ?? new RateLimitedQueue(this.opts.limit)
|
|
this.requests = this.opts.rateLimitedQueue ?? new RateLimitedQueue(this.opts.limit)
|
|
- this.#companionCommunicationQueue = new HTTPCommunicationQueue(this.requests, this.opts, this.#setS3MultipartState)
|
|
|
|
|
|
+ this.#companionCommunicationQueue = new HTTPCommunicationQueue(
|
|
|
|
+ this.requests,
|
|
|
|
+ this.opts,
|
|
|
|
+ this.#setS3MultipartState,
|
|
|
|
+ this.#getFile,
|
|
|
|
+ )
|
|
|
|
|
|
this.uploaders = Object.create(null)
|
|
this.uploaders = Object.create(null)
|
|
this.uploaderEvents = Object.create(null)
|
|
this.uploaderEvents = Object.create(null)
|
|
@@ -675,6 +692,11 @@ export default class AwsS3Multipart extends UploaderPlugin {
|
|
|
|
|
|
#setS3MultipartState = (file, { key, uploadId }) => {
|
|
#setS3MultipartState = (file, { key, uploadId }) => {
|
|
const cFile = this.uppy.getFile(file.id)
|
|
const cFile = this.uppy.getFile(file.id)
|
|
|
|
+ if (cFile == null) {
|
|
|
|
+ // file was removed from store
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
this.uppy.setFileState(file.id, {
|
|
this.uppy.setFileState(file.id, {
|
|
s3Multipart: {
|
|
s3Multipart: {
|
|
...cFile.s3Multipart,
|
|
...cFile.s3Multipart,
|
|
@@ -684,10 +706,12 @@ export default class AwsS3Multipart extends UploaderPlugin {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #getFile = (file) => {
|
|
|
|
+ return this.uppy.getFile(file.id) || file
|
|
|
|
+ }
|
|
|
|
+
|
|
#uploadFile (file) {
|
|
#uploadFile (file) {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- const getFile = () => this.uppy.getFile(file.id) || file
|
|
|
|
-
|
|
|
|
const onProgress = (bytesUploaded, bytesTotal) => {
|
|
const onProgress = (bytesUploaded, bytesTotal) => {
|
|
this.uppy.emit('upload-progress', file, {
|
|
this.uppy.emit('upload-progress', file, {
|
|
uploader: this,
|
|
uploader: this,
|
|
@@ -714,7 +738,7 @@ export default class AwsS3Multipart extends UploaderPlugin {
|
|
|
|
|
|
this.resetUploaderReferences(file.id)
|
|
this.resetUploaderReferences(file.id)
|
|
|
|
|
|
- this.uppy.emit('upload-success', getFile(), uploadResp)
|
|
|
|
|
|
+ this.uppy.emit('upload-success', this.#getFile(file), uploadResp)
|
|
|
|
|
|
if (result.location) {
|
|
if (result.location) {
|
|
this.uppy.log(`Download ${file.name} from ${result.location}`)
|
|
this.uppy.log(`Download ${file.name} from ${result.location}`)
|
|
@@ -724,7 +748,7 @@ export default class AwsS3Multipart extends UploaderPlugin {
|
|
}
|
|
}
|
|
|
|
|
|
const onPartComplete = (part) => {
|
|
const onPartComplete = (part) => {
|
|
- this.uppy.emit('s3-multipart:part-uploaded', getFile(), part)
|
|
|
|
|
|
+ this.uppy.emit('s3-multipart:part-uploaded', this.#getFile(file), part)
|
|
}
|
|
}
|
|
|
|
|
|
const upload = new MultipartUploader(file.data, {
|
|
const upload = new MultipartUploader(file.data, {
|