mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 14:53:13 +08:00
Followup 66cee823ab
Introduces a few basic system specs to verify that image optimization is
working as expected when uploading images via the composer. The specs
check
that images are optimized and that the optimization process completes
successfully
for both png and jpg images.
This PR also improves the formatting of optimization logs, including
adding
information about the original image size in bytes
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
onmessage = async function (e) {
|
|
switch (e.data.type) {
|
|
case "compress":
|
|
try {
|
|
globalThis.debugMode = e.data.settings.debug_mode;
|
|
|
|
let optimized = await globalThis.optimize(
|
|
e.data.file,
|
|
e.data.fileName,
|
|
e.data.width,
|
|
e.data.height,
|
|
e.data.originalFileSize,
|
|
e.data.settings
|
|
);
|
|
postMessage(
|
|
{
|
|
type: "file",
|
|
file: optimized,
|
|
fileName: e.data.fileName,
|
|
fileId: e.data.fileId,
|
|
},
|
|
[optimized]
|
|
);
|
|
} catch (error) {
|
|
console.error(error);
|
|
postMessage({
|
|
type: "error",
|
|
file: e.data.file,
|
|
fileName: e.data.fileName,
|
|
fileId: e.data.fileId,
|
|
});
|
|
}
|
|
break;
|
|
case "install":
|
|
try {
|
|
globalThis.document = {}; // webpack expects this to exist
|
|
await loadLibs(e.data.settings);
|
|
postMessage({ type: "installed" });
|
|
} catch (error) {
|
|
console.error(error);
|
|
postMessage({ type: "installFailed", errorMessage: error.message });
|
|
}
|
|
break;
|
|
default:
|
|
logIfDebug(`Sorry, we are out of ${e}.`);
|
|
}
|
|
};
|
|
|
|
async function loadLibs(settings) {
|
|
importScripts(settings.mediaOptimizationBundle);
|
|
}
|