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,
|
remote_url?: string,
|
||||||
thumbnail_url?: string,
|
thumbnail_url?: string,
|
||||||
title?: string,
|
title?: string,
|
||||||
|
// Temporary values
|
||||||
|
uploadUrl?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type FileUploadItem = {
|
declare type FileUploadItem = {
|
||||||
|
|
|
@ -164,6 +164,12 @@ export const publishReducer = handleActions(
|
||||||
if (progress) {
|
if (progress) {
|
||||||
currentUploads[key].progress = progress;
|
currentUploads[key].progress = progress;
|
||||||
delete currentUploads[key].status;
|
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) {
|
} else if (status) {
|
||||||
currentUploads[key].status = status;
|
currentUploads[key].status = status;
|
||||||
if (status === 'error') {
|
if (status === 'error') {
|
||||||
|
|
|
@ -23,10 +23,13 @@ export function makeResumableUploadRequest(
|
||||||
reject(new Error('Publish: v2 does not support remote_url'));
|
reject(new Error('Publish: v2 does not support remote_url'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const payloadParams = Object.assign({}, params);
|
||||||
|
delete payloadParams.uploadUrl; // cleanup
|
||||||
|
|
||||||
const jsonPayload = JSON.stringify({
|
const jsonPayload = JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: RESUMABLE_ENDPOINT_METHOD,
|
method: RESUMABLE_ENDPOINT_METHOD,
|
||||||
params,
|
params: payloadParams,
|
||||||
id: new Date().getTime(),
|
id: new Date().getTime(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,8 +95,9 @@ export function makeResumableUploadRequest(
|
||||||
uploader
|
uploader
|
||||||
.findPreviousUploads()
|
.findPreviousUploads()
|
||||||
.then((previousUploads) => {
|
.then((previousUploads) => {
|
||||||
if (previousUploads.length > 0) {
|
const index = previousUploads.findIndex((prev) => prev.uploadUrl === params.uploadUrl);
|
||||||
uploader.resumeFromPreviousUpload(previousUploads[0]);
|
if (index !== -1) {
|
||||||
|
uploader.resumeFromPreviousUpload(previousUploads[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPreview) {
|
if (!isPreview) {
|
||||||
|
|
Loading…
Reference in a new issue