@uppy/transloadit
Advanced tools
Comparing version 2.3.4 to 2.3.5
# @uppy/transloadit | ||
## 2.3.5 | ||
Released: 2022-07-27 | ||
Included in: Uppy v2.13.1 | ||
- @uppy/transloadit: cancel assemblies when all its files have been removed (Antoine du Hamel / #3893) | ||
## 2.3.4 | ||
@@ -4,0 +11,0 @@ |
@@ -74,3 +74,9 @@ "use strict"; | ||
} | ||
/** | ||
* @param {RequestInfo | URL} input | ||
* @param {RequestInit} init | ||
* @returns {Promise<any>} | ||
*/ | ||
/** | ||
@@ -164,2 +170,28 @@ * Create a new assembly. | ||
/** | ||
* Update the number of expected files in an already created assembly. | ||
* | ||
* @param {object} assembly | ||
* @param {number} num_expected_upload_files | ||
*/ | ||
updateNumberOfFilesInAssembly(assembly, num_expected_upload_files) { | ||
const url = new URL(assembly.assembly_ssl_url); | ||
url.pathname = '/update_assemblies'; | ||
const body = JSON.stringify({ | ||
assembly_updates: [{ | ||
assembly_id: assembly.assembly_id, | ||
num_expected_upload_files | ||
}] | ||
}); | ||
return _classPrivateFieldLooseBase(this, _fetchJSON)[_fetchJSON](url, { | ||
method: 'post', | ||
headers: _classPrivateFieldLooseBase(this, _headers)[_headers], | ||
body | ||
}).catch(err => _classPrivateFieldLooseBase(this, _reportError)[_reportError](err, { | ||
url, | ||
type: 'API_ERROR' | ||
})); | ||
} | ||
/** | ||
* Cancel a running Assembly. | ||
@@ -166,0 +198,0 @@ * |
@@ -39,3 +39,3 @@ "use strict"; | ||
const packageJson = { | ||
"version": "2.3.4" | ||
"version": "2.3.5" | ||
}; | ||
@@ -365,3 +365,4 @@ | ||
const assemblyOptions = new AssemblyOptions(filesWithoutErrors, this.opts); | ||
return assemblyOptions.build().then(assemblies => Promise.all(assemblies.map(createAssembly))).then(createdAssemblies => { | ||
return assemblyOptions.build().then(assemblies => Promise.all(assemblies.map(createAssembly))).then(maybeCreatedAssemblies => { | ||
const createdAssemblies = maybeCreatedAssemblies.filter(Boolean); | ||
const assemblyIDs = createdAssemblies.map(assembly => assembly.status.assembly_id); | ||
@@ -722,3 +723,21 @@ | ||
signature: options.signature | ||
}).then(newAssembly => { | ||
}).then(async newAssembly => { | ||
const files = this.uppy.getFiles().filter(_ref2 => { | ||
let { | ||
id | ||
} = _ref2; | ||
return fileIDs.includes(id); | ||
}); | ||
if (files.length !== fileIDs.length) { | ||
if (files.length === 0) { | ||
// All files have been removed, cancelling. | ||
await this.client.cancelAssembly(newAssembly); | ||
return null; | ||
} // At least one file has been removed. | ||
await this.client.updateNumberOfFilesInAssembly(newAssembly, files.length); | ||
} | ||
const assembly = new Assembly(newAssembly, _classPrivateFieldLooseBase(this, _rateLimitedQueue)[_rateLimitedQueue]); | ||
@@ -743,4 +762,2 @@ const { | ||
}); | ||
const files = this.uppy.getFiles(); // [] | ||
const updatedFiles = {}; | ||
@@ -759,9 +776,20 @@ files.forEach(file => { | ||
assembly.close(); | ||
this.client.cancelAssembly(newAssembly).catch(() => { | ||
/* ignore potential errors */ | ||
}); | ||
this.uppy.off(fileRemovedHandler); | ||
} else if (fileRemoved.id in updatedFiles) { | ||
delete updatedFiles[fileRemoved.id]; | ||
const nbOfRemainingFiles = Object.keys(updatedFiles).length; | ||
if (Object.keys(updatedFiles).length === 0) { | ||
if (nbOfRemainingFiles === 0) { | ||
assembly.close(); | ||
this.client.cancelAssembly(newAssembly).catch(() => { | ||
/* ignore potential errors */ | ||
}); | ||
this.uppy.off(fileRemovedHandler); | ||
} else { | ||
this.client.updateNumberOfFilesInAssembly(newAssembly, nbOfRemainingFiles).catch(() => { | ||
/* ignore potential errors */ | ||
}); | ||
} | ||
@@ -768,0 +796,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": "2.3.4", | ||
"version": "2.3.5", | ||
"license": "MIT", | ||
@@ -39,3 +39,3 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"@uppy/core": "^2.3.1" | ||
"@uppy/core": "^2.3.2" | ||
}, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
@@ -23,2 +23,7 @@ import fetchWithNetworkError from '@uppy/utils/lib/fetchWithNetworkError' | ||
/** | ||
* @param {RequestInfo | URL} input | ||
* @param {RequestInit} init | ||
* @returns {Promise<any>} | ||
*/ | ||
#fetchJSON (...args) { | ||
@@ -131,2 +136,21 @@ return this.#fetchWithNetworkError(...args).then(response => { | ||
/** | ||
* Update the number of expected files in an already created assembly. | ||
* | ||
* @param {object} assembly | ||
* @param {number} num_expected_upload_files | ||
*/ | ||
updateNumberOfFilesInAssembly (assembly, num_expected_upload_files) { | ||
const url = new URL(assembly.assembly_ssl_url) | ||
url.pathname = '/update_assemblies' | ||
const body = JSON.stringify({ | ||
assembly_updates: [{ | ||
assembly_id: assembly.assembly_id, | ||
num_expected_upload_files, | ||
}], | ||
}) | ||
return this.#fetchJSON(url, { method: 'post', headers: this.#headers, body }) | ||
.catch((err) => this.#reportError(err, { url, type: 'API_ERROR' })) | ||
} | ||
/** | ||
* Cancel a running Assembly. | ||
@@ -133,0 +157,0 @@ * |
@@ -193,3 +193,14 @@ import hasProperty from '@uppy/utils/lib/hasProperty' | ||
signature: options.signature, | ||
}).then((newAssembly) => { | ||
}).then(async (newAssembly) => { | ||
const files = this.uppy.getFiles().filter(({ id }) => fileIDs.includes(id)) | ||
if (files.length !== fileIDs.length) { | ||
if (files.length === 0) { | ||
// All files have been removed, cancelling. | ||
await this.client.cancelAssembly(newAssembly) | ||
return null | ||
} | ||
// At least one file has been removed. | ||
await this.client.updateNumberOfFilesInAssembly(newAssembly, files.length) | ||
} | ||
const assembly = new Assembly(newAssembly, this.#rateLimitedQueue) | ||
@@ -216,3 +227,2 @@ const { status } = assembly | ||
const files = this.uppy.getFiles() // [] | ||
const updatedFiles = {} | ||
@@ -233,8 +243,14 @@ files.forEach((file) => { | ||
assembly.close() | ||
this.client.cancelAssembly(newAssembly).catch(() => { /* ignore potential errors */ }) | ||
this.uppy.off(fileRemovedHandler) | ||
} else if (fileRemoved.id in updatedFiles) { | ||
delete updatedFiles[fileRemoved.id] | ||
if (Object.keys(updatedFiles).length === 0) { | ||
const nbOfRemainingFiles = Object.keys(updatedFiles).length | ||
if (nbOfRemainingFiles === 0) { | ||
assembly.close() | ||
this.client.cancelAssembly(newAssembly).catch(() => { /* ignore potential errors */ }) | ||
this.uppy.off(fileRemovedHandler) | ||
} else { | ||
this.client.updateNumberOfFilesInAssembly(newAssembly, nbOfRemainingFiles) | ||
.catch(() => { /* ignore potential errors */ }) | ||
} | ||
@@ -639,3 +655,4 @@ } | ||
.then((assemblies) => Promise.all(assemblies.map(createAssembly))) | ||
.then((createdAssemblies) => { | ||
.then((maybeCreatedAssemblies) => { | ||
const createdAssemblies = maybeCreatedAssemblies.filter(Boolean) | ||
const assemblyIDs = createdAssemblies.map(assembly => assembly.status.assembly_id) | ||
@@ -642,0 +659,0 @@ this.#createAssemblyWatcher(assemblyIDs, uploadID) |
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
239098
3619