FIX: Use file.id instead of file.name for media-optimization resolvers (#14110)

This change only applies when uppy is calling the media-optimization-worker.

Since the old way of calling the worker via jQuery file uploader will
be removed soon, there is no point coming up with some random string
to use in place of the file name for the promise resolvers there, we
can live with this for now.
This commit is contained in:
Martin Brennan 2021-08-23 12:10:33 +10:00 committed by GitHub
parent 2ab4f2a126
commit 8989c9e6c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -60,7 +60,7 @@ export default class MediaOptimizationWorkerService extends Service {
this.logIfDebug(`Transforming ${file.name}`);
this.currentComposerUploadData = data;
this.promiseResolvers[file.name] = resolve;
this.promiseResolvers[this.usingUppy ? file.id : file.name] = resolve;
let imageData;
try {
@ -77,6 +77,7 @@ export default class MediaOptimizationWorkerService extends Service {
this.worker.postMessage(
{
type: "compress",
fileId: file.id,
file: imageData.data.buffer,
fileName: file.name,
width: imageData.width,
@ -117,7 +118,7 @@ export default class MediaOptimizationWorkerService extends Service {
this.worker.onmessage = (e) => {
switch (e.data.type) {
case "file":
let optimizedFile = new File([e.data.file], `${e.data.fileName}`, {
let optimizedFile = new File([e.data.file], e.data.fileName, {
type: "image/jpeg",
});
this.logIfDebug(
@ -125,7 +126,7 @@ export default class MediaOptimizationWorkerService extends Service {
);
if (this.usingUppy) {
this.promiseResolvers[optimizedFile.name](optimizedFile);
this.promiseResolvers[e.data.fileId](optimizedFile);
} else {
let data = this.currentComposerUploadData;
data.files[data.index] = optimizedFile;
@ -143,7 +144,7 @@ export default class MediaOptimizationWorkerService extends Service {
}
if (this.usingUppy) {
this.promiseResolvers[e.data.fileName]();
this.promiseResolvers[e.data.fileId]();
} else {
this.promiseResolvers[e.data.fileName](
this.currentComposerUploadData

View File

@ -131,7 +131,8 @@ onmessage = async function (e) {
{
type: "file",
file: optimized,
fileName: e.data.fileName
fileName: e.data.fileName,
fileId: e.data.fileId
},
[optimized]
);
@ -140,7 +141,8 @@ onmessage = async function (e) {
postMessage({
type: "error",
file: e.data.file,
fileName: e.data.fileName
fileName: e.data.fileName,
fileId: e.data.fileId
});
}
break;