diff --git a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js index 1cac1783573..f2e82584761 100644 --- a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js +++ b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js @@ -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 diff --git a/public/javascripts/media-optimization-worker.js b/public/javascripts/media-optimization-worker.js index 3ed3c52a61a..189a88b761f 100644 --- a/public/javascripts/media-optimization-worker.js +++ b/public/javascripts/media-optimization-worker.js @@ -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;