TUS: fix parallel uploads of the same file
## Issue If you make 2 claims from the same source file, the second upload thinks it's trying to resume from the first one. They should be unique uploads. ## Approach Stash the upload url for comparison when looking up existing uploads to resume. Stash that in `params` to minimize code changes. We'll just need to ensure it is cleared before we generate the SDK payload.
This commit is contained in:
parent
861aaf4cde
commit
dfe30b6d78
3 changed files with 15 additions and 3 deletions
2
flow-typed/publish.js
vendored
2
flow-typed/publish.js
vendored
|
@ -62,6 +62,8 @@ declare type FileUploadSdkParams = {
|
|||
remote_url?: string,
|
||||
thumbnail_url?: string,
|
||||
title?: string,
|
||||
// Temporary values
|
||||
uploadUrl?: string,
|
||||
};
|
||||
|
||||
declare type FileUploadItem = {
|
||||
|
|
|
@ -164,6 +164,12 @@ export const publishReducer = handleActions(
|
|||
if (progress) {
|
||||
currentUploads[key].progress = progress;
|
||||
delete currentUploads[key].status;
|
||||
|
||||
if (currentUploads[key].uploader.url && !currentUploads[key].params.uploadUrl) {
|
||||
// TUS has finally obtained an upload url from the server. Stash that to check later when resuming.
|
||||
// Ignoring immutable-update requirement (probably doesn't matter to the GUI).
|
||||
currentUploads[key].params.uploadUrl = currentUploads[key].uploader.url;
|
||||
}
|
||||
} else if (status) {
|
||||
currentUploads[key].status = status;
|
||||
if (status === 'error') {
|
||||
|
|
|
@ -23,10 +23,13 @@ export function makeResumableUploadRequest(
|
|||
reject(new Error('Publish: v2 does not support remote_url'));
|
||||
}
|
||||
|
||||
const payloadParams = Object.assign({}, params);
|
||||
delete payloadParams.uploadUrl; // cleanup
|
||||
|
||||
const jsonPayload = JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
method: RESUMABLE_ENDPOINT_METHOD,
|
||||
params,
|
||||
params: payloadParams,
|
||||
id: new Date().getTime(),
|
||||
});
|
||||
|
||||
|
@ -92,8 +95,9 @@ export function makeResumableUploadRequest(
|
|||
uploader
|
||||
.findPreviousUploads()
|
||||
.then((previousUploads) => {
|
||||
if (previousUploads.length > 0) {
|
||||
uploader.resumeFromPreviousUpload(previousUploads[0]);
|
||||
const index = previousUploads.findIndex((prev) => prev.uploadUrl === params.uploadUrl);
|
||||
if (index !== -1) {
|
||||
uploader.resumeFromPreviousUpload(previousUploads[index]);
|
||||
}
|
||||
|
||||
if (!isPreview) {
|
||||
|
|
Loading…
Reference in a new issue