@uppy/tus
Advanced tools
Comparing version 3.1.1 to 3.1.2
# @uppy/tus | ||
## 3.1.2 | ||
Released: 2023-07-06 | ||
Included in: Uppy v3.11.0 | ||
- @uppy/tus: retry on 423 HTTP error code (Antoine du Hamel / #4512) | ||
## 3.1.1 | ||
@@ -4,0 +11,0 @@ |
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
var id = 0; | ||
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } | ||
import BasePlugin from '@uppy/core/lib/BasePlugin.js'; | ||
import UploaderPlugin from '@uppy/core/lib/UploaderPlugin.js'; | ||
import * as tus from 'tus-js-client'; | ||
@@ -17,3 +17,3 @@ import { Provider, RequestClient, Socket } from '@uppy/companion-client'; | ||
const packageJson = { | ||
"version": "3.1.1" | ||
"version": "3.1.2" | ||
}; | ||
@@ -55,9 +55,7 @@ /** @typedef {import('..').TusOptions} TusOptions */ | ||
var _retryDelayIterator = /*#__PURE__*/_classPrivateFieldLooseKey("retryDelayIterator"); | ||
var _queueRequestSocketToken = /*#__PURE__*/_classPrivateFieldLooseKey("queueRequestSocketToken"); | ||
var _upload = /*#__PURE__*/_classPrivateFieldLooseKey("upload"); | ||
var _requestSocketToken = /*#__PURE__*/_classPrivateFieldLooseKey("requestSocketToken"); | ||
var _uploadRemote = /*#__PURE__*/_classPrivateFieldLooseKey("uploadRemote"); | ||
var _uploadFiles = /*#__PURE__*/_classPrivateFieldLooseKey("uploadFiles"); | ||
var _handleUpload = /*#__PURE__*/_classPrivateFieldLooseKey("handleUpload"); | ||
export default class Tus extends BasePlugin { | ||
export default class Tus extends UploaderPlugin { | ||
/** | ||
@@ -76,12 +74,3 @@ * @param {Uppy} uppy | ||
}); | ||
// NOTE! Keep this duplicated code in sync with other plugins | ||
// TODO we should probably abstract this into a common function | ||
/** | ||
* @param {UppyFile} file for use with upload | ||
* @returns {Promise<void>} | ||
*/ | ||
Object.defineProperty(this, _uploadRemote, { | ||
value: _uploadRemote2 | ||
}); | ||
/** | ||
* Create a new Tus upload. | ||
@@ -128,6 +117,2 @@ * | ||
}); | ||
Object.defineProperty(this, _queueRequestSocketToken, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, _requestSocketToken, { | ||
@@ -211,5 +196,5 @@ writable: true, | ||
this.handleResetProgress = this.handleResetProgress.bind(this); | ||
_classPrivateFieldLooseBase(this, _queueRequestSocketToken)[_queueRequestSocketToken] = this.requests.wrapPromiseFunction(_classPrivateFieldLooseBase(this, _requestSocketToken)[_requestSocketToken], { | ||
this.setQueueRequestSocketToken(this.requests.wrapPromiseFunction(_classPrivateFieldLooseBase(this, _requestSocketToken)[_requestSocketToken], { | ||
priority: -1 | ||
}); | ||
})); | ||
} | ||
@@ -630,4 +615,6 @@ handleResetProgress() { | ||
} | ||
} else if (status > 400 && status < 500 && status !== 409) { | ||
} else if (status > 400 && status < 500 && status !== 409 && status !== 423) { | ||
// HTTP 4xx, the server won't send anything, it's doesn't make sense to retry | ||
// HTTP 409 Conflict (happens if the Upload-Offset header does not match the one on the server) | ||
// HTTP 423 Locked (happens when a paused download is resumed too quickly) | ||
return false; | ||
@@ -761,27 +748,2 @@ } else if (typeof navigator !== 'undefined' && navigator.onLine === false) { | ||
} | ||
async function _uploadRemote2(file, options) { | ||
this.resetUploaderReferences(file.id); | ||
try { | ||
if (file.serverToken) { | ||
return await this.connectToServerSocket(file); | ||
} | ||
const serverToken = await _classPrivateFieldLooseBase(this, _queueRequestSocketToken)[_queueRequestSocketToken](file, options).abortOn(options == null ? void 0 : 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) { | ||
var _err$cause; | ||
if ((err == null ? void 0 : (_err$cause = err.cause) == null ? void 0 : _err$cause.name) !== 'AbortError') { | ||
this.uppy.setFileState(file.id, { | ||
serverToken: undefined | ||
}); | ||
this.uppy.emit('upload-error', file, err); | ||
throw err; | ||
} | ||
// The file upload was aborted, it’s not an error | ||
return undefined; | ||
} | ||
} | ||
async function _uploadFiles2(files) { | ||
@@ -800,3 +762,4 @@ const filesFiltered = filterNonFailedFiles(files); | ||
this.uppy.on('file-removed', removedHandler); | ||
const uploadPromise = _classPrivateFieldLooseBase(this, _uploadRemote)[_uploadRemote](file, { | ||
this.resetUploaderReferences(file.id); | ||
const uploadPromise = this.uploadRemoteFile(file, { | ||
signal: controller.signal | ||
@@ -803,0 +766,0 @@ }); |
{ | ||
"name": "@uppy/tus", | ||
"description": "Resumable uploads for Uppy using Tus.io", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"license": "MIT", | ||
@@ -26,3 +26,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/companion-client": "^3.1.3", | ||
"@uppy/companion-client": "^3.2.0", | ||
"@uppy/utils": "^5.4.0", | ||
@@ -35,4 +35,4 @@ "tus-js-client": "^3.0.0" | ||
"peerDependencies": { | ||
"@uppy/core": "^3.2.1" | ||
"@uppy/core": "^3.3.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import BasePlugin from '@uppy/core/lib/BasePlugin.js' | ||
import UploaderPlugin from '@uppy/core/lib/UploaderPlugin.js' | ||
import * as tus from 'tus-js-client' | ||
@@ -55,3 +55,3 @@ import { Provider, RequestClient, Socket } from '@uppy/companion-client' | ||
*/ | ||
export default class Tus extends BasePlugin { | ||
export default class Tus extends UploaderPlugin { | ||
static VERSION = packageJson.version | ||
@@ -61,4 +61,2 @@ | ||
#queueRequestSocketToken | ||
/** | ||
@@ -107,3 +105,3 @@ * @param {Uppy} uppy | ||
this.handleResetProgress = this.handleResetProgress.bind(this) | ||
this.#queueRequestSocketToken = this.requests.wrapPromiseFunction(this.#requestSocketToken, { priority: -1 }) | ||
this.setQueueRequestSocketToken(this.requests.wrapPromiseFunction(this.#requestSocketToken, { priority: -1 })) | ||
} | ||
@@ -308,4 +306,6 @@ | ||
} | ||
} else if (status > 400 && status < 500 && status !== 409) { | ||
} else if (status > 400 && status < 500 && status !== 409 && status !== 423) { | ||
// HTTP 4xx, the server won't send anything, it's doesn't make sense to retry | ||
// HTTP 409 Conflict (happens if the Upload-Offset header does not match the one on the server) | ||
// HTTP 423 Locked (happens when a paused download is resumed too quickly) | ||
return false | ||
@@ -460,33 +460,3 @@ } else if (typeof navigator !== 'undefined' && navigator.onLine === false) { | ||
// NOTE! Keep this duplicated code in sync with other plugins | ||
// TODO we should probably abstract this into a common function | ||
/** | ||
* @param {UppyFile} file for use with upload | ||
* @returns {Promise<void>} | ||
*/ | ||
async #uploadRemote (file, options) { | ||
this.resetUploaderReferences(file.id) | ||
try { | ||
if (file.serverToken) { | ||
return await this.connectToServerSocket(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) { | ||
if (err?.cause?.name !== 'AbortError') { | ||
this.uppy.setFileState(file.id, { serverToken: undefined }) | ||
this.uppy.emit('upload-error', file, err) | ||
throw err | ||
} | ||
// The file upload was aborted, it’s not an error | ||
return undefined | ||
} | ||
} | ||
/** | ||
* See the comment on the upload() method. | ||
@@ -751,3 +721,4 @@ * | ||
const uploadPromise = this.#uploadRemote(file, { signal: controller.signal }) | ||
this.resetUploaderReferences(file.id) | ||
const uploadPromise = this.uploadRemoteFile(file, { signal: controller.signal }) | ||
@@ -754,0 +725,0 @@ this.requests.wrapSyncFunction(() => { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117765
1516