mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:33:51 +08:00
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:
parent
2ab4f2a126
commit
8989c9e6c9
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user