Merge pull request #14246 from mvdbeek/tus_robustness_22_01

[22.01] Improve robustness of tus upload and calculation of progress
This commit is contained in:
Marius van den Beek
2022-07-02 16:27:33 +02:00
committed by GitHub
+19 -6
View File
@@ -39,16 +39,25 @@ function tusUpload(data, index, tusEndpoint, cnf) {
console.debug(`Starting chunked upload for ${file.name} [chunkSize=${chunkSize}].`);
const upload = new tus.Upload(file, {
endpoint: tusEndpoint,
retryDelays: [0, 3000, 10000],
fingerprint: buildFingerprint(cnf),
chunkSize: chunkSize,
metadata: data.payload,
onError: function (error) {
console.log("Failed because: " + error);
cnf.error(error);
onError: function (err) {
const status = err.originalResponse?.getStatus();
if (status == 403) {
console.error(`Failed because of missing authorization: ${err}`);
cnf.error(err);
} else {
// 🎵 Never gonna give you up 🎵
console.log(`Failed because: ${err}\n, will retry in 10 seconds`);
setTimeout(() => startTusUpload(upload), 10000);
}
},
onProgress: function (bytesUploaded, bytesTotal) {
var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
console.log(bytesUploaded, bytesTotal, percentage + "%");
onChunkComplete: function (chunkSize, bytesAccepted, bytesTotal) {
const percentage = ((bytesAccepted / bytesTotal) * 100).toFixed(2);
console.log(bytesAccepted, bytesTotal, percentage + "%");
cnf.progress(percentage);
},
onSuccess: function () {
@@ -62,6 +71,10 @@ function tusUpload(data, index, tusEndpoint, cnf) {
tusUpload(data, index + 1, tusEndpoint, cnf);
},
});
startTusUpload(upload);
}
function startTusUpload(upload) {
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.