@uppy/transloadit
Advanced tools
Comparing version 3.1.6 to 3.2.0
# @uppy/transloadit | ||
## 3.2.0 | ||
Released: 2023-07-13 | ||
Included in: Uppy v3.12.0 | ||
- @uppy/transloadit: fix error message (Antoine du Hamel / #4572) | ||
- @uppy/transloadit: implement Server-sent event API (Antoine du Hamel / #4098) | ||
## 3.1.6 | ||
@@ -4,0 +12,0 @@ |
@@ -31,3 +31,5 @@ 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 _previousFetchStatusStillPending = /*#__PURE__*/_classPrivateFieldLooseKey("previousFetchStatusStillPending"); | ||
var _sse = /*#__PURE__*/_classPrivateFieldLooseKey("sse"); | ||
var _onFinished = /*#__PURE__*/_classPrivateFieldLooseKey("onFinished"); | ||
var _connectServerSentEvents = /*#__PURE__*/_classPrivateFieldLooseKey("connectServerSentEvents"); | ||
var _connectSocket = /*#__PURE__*/_classPrivateFieldLooseKey("connectSocket"); | ||
@@ -77,2 +79,5 @@ var _onError = /*#__PURE__*/_classPrivateFieldLooseKey("onError"); | ||
}); | ||
Object.defineProperty(this, _connectServerSentEvents, { | ||
value: _connectServerSentEvents2 | ||
}); | ||
Object.defineProperty(this, _onFinished, { | ||
@@ -93,2 +98,6 @@ value: _onFinished2 | ||
}); | ||
Object.defineProperty(this, _sse, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.status = assembly; | ||
@@ -105,2 +114,3 @@ // The socket.io connection. | ||
connect() { | ||
_classPrivateFieldLooseBase(this, _connectServerSentEvents)[_connectServerSentEvents](); | ||
_classPrivateFieldLooseBase(this, _connectSocket)[_connectSocket](); | ||
@@ -130,2 +140,6 @@ _classPrivateFieldLooseBase(this, _beginPolling)[_beginPolling](); | ||
this.closed = true; | ||
if (_classPrivateFieldLooseBase(this, _sse)[_sse]) { | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].close(); | ||
_classPrivateFieldLooseBase(this, _sse)[_sse] = null; | ||
} | ||
if (this.socket) { | ||
@@ -143,2 +157,59 @@ this.socket.disconnect(); | ||
} | ||
function _connectServerSentEvents2() { | ||
_classPrivateFieldLooseBase(this, _sse)[_sse] = new EventSource(`${this.status.websocket_url}?assembly=${this.status.assembly_id}`); | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].addEventListener('open', () => { | ||
// if server side events works, we don't need websockets anymore (it's just a fallback) | ||
if (this.socket) { | ||
this.socket.disconnect(); | ||
this.socket = null; | ||
} | ||
clearInterval(this.pollInterval); | ||
this.pollInterval = null; | ||
}); | ||
/* | ||
* The event "message" is a special case, as it | ||
* will capture events without an event field | ||
* as well as events that have the specific type | ||
* other event type. | ||
*/ | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].addEventListener('message', e => { | ||
if (e.data === 'assembly_finished') { | ||
_classPrivateFieldLooseBase(this, _onFinished)[_onFinished](); | ||
} | ||
if (e.data === 'assembly_uploading_finished') { | ||
this.emit('executing'); | ||
} | ||
if (e.data === 'assembly_upload_meta_data_extracted') { | ||
this.emit('metadata'); | ||
_classPrivateFieldLooseBase(this, _fetchStatus)[_fetchStatus]({ | ||
diff: false | ||
}); | ||
} | ||
}); | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].addEventListener('assembly_upload_finished', e => { | ||
const file = JSON.parse(e.data); | ||
this.emit('upload', file); | ||
this.status.uploads.push(file); | ||
}); | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].addEventListener('assembly_result_finished', e => { | ||
var _this$status$results, _this$status$results$; | ||
const [stepName, result] = JSON.parse(e.data); | ||
this.emit('result', stepName, result); | ||
((_this$status$results$ = (_this$status$results = this.status.results)[stepName]) != null ? _this$status$results$ : _this$status$results[stepName] = []).push(result); | ||
}); | ||
_classPrivateFieldLooseBase(this, _sse)[_sse].addEventListener('assembly_error', e => { | ||
try { | ||
_classPrivateFieldLooseBase(this, _onError)[_onError](JSON.parse(e.data)); | ||
} catch { | ||
_classPrivateFieldLooseBase(this, _onError)[_onError]({ | ||
msg: e.data | ||
}); | ||
} | ||
// Refetch for updated status code | ||
_classPrivateFieldLooseBase(this, _fetchStatus)[_fetchStatus]({ | ||
diff: false | ||
}); | ||
}); | ||
} | ||
function _connectSocket2() { | ||
@@ -177,7 +248,5 @@ const parsed = parseUrl(this.status.websocket_url); | ||
socket.on('assembly_result_finished', (stepName, result) => { | ||
var _this$status$results2, _this$status$results3; | ||
this.emit('result', stepName, result); | ||
if (!this.status.results[stepName]) { | ||
this.status.results[stepName] = []; | ||
} | ||
this.status.results[stepName].push(result); | ||
((_this$status$results3 = (_this$status$results2 = this.status.results)[stepName]) != null ? _this$status$results3 : _this$status$results2[stepName] = []).push(result); | ||
}); | ||
@@ -184,0 +253,0 @@ socket.on('assembly_error', status => { |
@@ -15,3 +15,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
const packageJson = { | ||
"version": "3.1.6" | ||
"version": "3.2.0" | ||
}; | ||
@@ -442,6 +442,6 @@ const sendErrorToConsole = originalErr => err => { | ||
var _file$transloadit2, _err$message; | ||
_classPrivateFieldLooseBase(this, _closeAssemblyIfExists)[_closeAssemblyIfExists](file == null ? void 0 : (_file$transloadit2 = file.transloadit) == null ? void 0 : _file$transloadit2.assembly); | ||
_classPrivateFieldLooseBase(this, _closeAssemblyIfExists)[_closeAssemblyIfExists](file == null || (_file$transloadit2 = file.transloadit) == null ? void 0 : _file$transloadit2.assembly); | ||
if (err != null && (_err$message = err.message) != null && _err$message.startsWith('tus: ')) { | ||
var _err$originalRequest, _err$originalRequest$; | ||
const endpoint = (_err$originalRequest = err.originalRequest) == null ? void 0 : (_err$originalRequest$ = _err$originalRequest.getUnderlyingObject()) == null ? void 0 : _err$originalRequest$.responseURL; | ||
var _err$originalRequest; | ||
const endpoint = (_err$originalRequest = err.originalRequest) == null || (_err$originalRequest = _err$originalRequest.getUnderlyingObject()) == null ? void 0 : _err$originalRequest.responseURL; | ||
this.client.submitError(err, { | ||
@@ -598,3 +598,3 @@ endpoint, | ||
var _file$transloadit3; | ||
return (file == null ? void 0 : (_file$transloadit3 = file.transloadit) == null ? void 0 : _file$transloadit3.assembly) === assemblyID; | ||
return (file == null || (_file$transloadit3 = file.transloadit) == null ? void 0 : _file$transloadit3.assembly) === assemblyID; | ||
}); | ||
@@ -841,3 +841,3 @@ } | ||
if (!file) { | ||
this.uppy.log('[Transloadit] Couldn’t file the file, it was likely removed in the process'); | ||
this.uppy.log('[Transloadit] Couldn’t find the file, it was likely removed in the process'); | ||
return; | ||
@@ -844,0 +844,0 @@ } |
{ | ||
"name": "@uppy/transloadit", | ||
"description": "The Transloadit plugin can be used to upload files to Transloadit for all kinds of processing, such as transcoding video, resizing images, zipping/unzipping, and more", | ||
"version": "3.1.6", | ||
"version": "3.2.0", | ||
"license": "MIT", | ||
@@ -31,6 +31,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/companion-client": "^3.1.3", | ||
"@uppy/provider-views": "^3.3.1", | ||
"@uppy/tus": "^3.1.1", | ||
"@uppy/utils": "^5.4.0", | ||
"@uppy/companion-client": "^3.2.1", | ||
"@uppy/provider-views": "^3.4.0", | ||
"@uppy/tus": "^3.1.2", | ||
"@uppy/utils": "^5.4.1", | ||
"component-emitter": "^1.2.1", | ||
@@ -40,3 +40,3 @@ "socket.io-client": "^4.1.3" | ||
"peerDependencies": { | ||
"@uppy/core": "^3.2.1" | ||
"@uppy/core": "^3.3.1" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -39,2 +39,4 @@ import Emitter from 'component-emitter' | ||
#sse | ||
constructor (assembly, rateLimitedQueue) { | ||
@@ -57,2 +59,3 @@ super() | ||
connect () { | ||
this.#connectServerSentEvents() | ||
this.#connectSocket() | ||
@@ -67,2 +70,59 @@ this.#beginPolling() | ||
#connectServerSentEvents () { | ||
this.#sse = new EventSource(`${this.status.websocket_url}?assembly=${this.status.assembly_id}`) | ||
this.#sse.addEventListener('open', () => { | ||
// if server side events works, we don't need websockets anymore (it's just a fallback) | ||
if (this.socket) { | ||
this.socket.disconnect() | ||
this.socket = null | ||
} | ||
clearInterval(this.pollInterval) | ||
this.pollInterval = null | ||
}) | ||
/* | ||
* The event "message" is a special case, as it | ||
* will capture events without an event field | ||
* as well as events that have the specific type | ||
* other event type. | ||
*/ | ||
this.#sse.addEventListener('message', (e) => { | ||
if (e.data === 'assembly_finished') { | ||
this.#onFinished() | ||
} | ||
if (e.data === 'assembly_uploading_finished') { | ||
this.emit('executing') | ||
} | ||
if (e.data === 'assembly_upload_meta_data_extracted') { | ||
this.emit('metadata') | ||
this.#fetchStatus({ diff: false }) | ||
} | ||
}) | ||
this.#sse.addEventListener('assembly_upload_finished', (e) => { | ||
const file = JSON.parse(e.data) | ||
this.emit('upload', file) | ||
this.status.uploads.push(file) | ||
}) | ||
this.#sse.addEventListener('assembly_result_finished', (e) => { | ||
const [stepName, result] = JSON.parse(e.data) | ||
this.emit('result', stepName, result) | ||
;(this.status.results[stepName] ??= []).push(result) | ||
}) | ||
this.#sse.addEventListener('assembly_error', (e) => { | ||
try { | ||
this.#onError(JSON.parse(e.data)) | ||
} catch { | ||
this.#onError({ msg: e.data }) | ||
} | ||
// Refetch for updated status code | ||
this.#fetchStatus({ diff: false }) | ||
}) | ||
} | ||
#connectSocket () { | ||
@@ -108,6 +168,3 @@ const parsed = parseUrl(this.status.websocket_url) | ||
this.emit('result', stepName, result) | ||
if (!this.status.results[stepName]) { | ||
this.status.results[stepName] = [] | ||
} | ||
this.status.results[stepName].push(result) | ||
;(this.status.results[stepName] ??= []).push(result) | ||
}) | ||
@@ -269,2 +326,6 @@ | ||
this.closed = true | ||
if (this.#sse) { | ||
this.#sse.close() | ||
this.#sse = null | ||
} | ||
if (this.socket) { | ||
@@ -271,0 +332,0 @@ this.socket.disconnect() |
@@ -382,3 +382,3 @@ import hasProperty from '@uppy/utils/lib/hasProperty' | ||
if (!file) { | ||
this.uppy.log('[Transloadit] Couldn’t file the file, it was likely removed in the process') | ||
this.uppy.log('[Transloadit] Couldn’t find the file, it was likely removed in the process') | ||
return | ||
@@ -385,0 +385,0 @@ } |
Sorry, the diff of this file is not supported yet
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
267004
3944
+ Addedengine.io-client@6.6.1(transitive)
- Removedengine.io-client@6.6.2(transitive)
Updated@uppy/provider-views@^3.4.0
Updated@uppy/tus@^3.1.2
Updated@uppy/utils@^5.4.1