Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Client-side JXL, HEIC, and animated GIF conversion (#39014)

Rafael dos Santos Silvae5df5fe10bfb
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index d711d4d186f..667cbbc9a58 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2197,6 +2197,8 @@ en:
composer_media_optimization_image_resize_dimensions_threshold: "Minimum image width to trigger client-side resize"
composer_media_optimization_image_resize_width_target: "Images with widths larger than `composer_media_optimization_image_dimensions_resize_threshold` will be resized to this width. Must be >= than `composer_media_optimization_image_dimensions_resize_threshold`."
composer_media_optimization_image_encode_quality: "JPG encode quality used in the re-encode process."
+ composer_media_optimization_image_convert_enabled: "Enables client-side conversion of JXL, HEIC, and animated GIF images before upload. JXL and HEIC are converted to JPEG, animated GIFs larger than the threshold are converted to animated WEBP."
+ composer_media_optimization_gif_conversion_threshold: "Minimum GIF file size in bytes to trigger client-side conversion to animated WEBP."
video_conversion_enabled: "Enable video conversion for uploaded video files. This allows videos to be converted to web-compatible formats."
video_conversion_service: "The video conversion service to use for processing uploaded videos."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index aae32406195..6ba1530f804 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -2257,7 +2257,7 @@ files:
list_type: file_types
authorized_extensions:
client: true
- default: "jpg|jpeg|png|gif|heic|heif|webp|avif|svg"
+ default: "jpg|jpeg|png|gif|heic|heif|webp|avif|svg|jxl"
refresh: true
type: list
list_type: file_types
@@ -2526,6 +2526,18 @@ files:
default: 0
client: true
hidden: true
+ composer_media_optimization_image_convert_enabled:
+ default: false
+ hidden: true
+ client: true
+ upcoming_change:
+ status: "experimental"
+ impact: "feature,all_members"
+ disallow_enabled_for_groups: true
+ composer_media_optimization_gif_conversion_threshold:
+ default: 512000
+ hidden: true
+ client: true
composer_media_optimization_debug_mode:
default: false
client: true
diff --git a/frontend/discourse/app/lib/uploads.js b/frontend/discourse/app/lib/uploads.js
index 7b5b1f77fdf..2efd31b7fa2 100644
--- a/frontend/discourse/app/lib/uploads.js
+++ b/frontend/discourse/app/lib/uploads.js
@@ -202,7 +202,7 @@ export function authorizedExtensions(staff, siteSettings) {
function authorizedImagesExtensions(staff, siteSettings) {
return authorizesAllExtensions(staff, siteSettings)
- ? "png, jpg, jpeg, gif, svg, ico, heic, heif, webp, avif"
+ ? "png, jpg, jpeg, gif, svg, ico, heic, heif, webp, avif, jxl"
: imagesExtensions(staff, siteSettings).join(", ");
}
@@ -236,7 +236,7 @@ export function authorizesOneOrMoreImageExtensions(staff, siteSettings) {
}
export function isImage(path) {
- return /\.(png|webp|jpe?g|gif|svg|ico|heic|heif|avif)$/i.test(path);
+ return /\.(png|webp|jpe?g|gif|svg|ico|heic|heif|avif|jxl)$/i.test(path);
}
export function isVideo(path) {
diff --git a/frontend/discourse/app/services/media-optimization-worker.js b/frontend/discourse/app/services/media-optimization-worker.js
index 2e75ab942aa..6000c08001f 100644
--- a/frontend/discourse/app/services/media-optimization-worker.js
+++ b/frontend/discourse/app/services/media-optimization-worker.js
@@ -6,6 +6,10 @@ import { fileToImageData } from "discourse/lib/media-optimization-utils";
const WORKER_INSTALL_TIMEOUT_MS = 3000;
+const CONVERT_FORMAT_REGEX = /(\.|\/)(jxl|hei[cf])$/i;
+const ANIMATED_GIF_REGEX = /(\.|\/)(gif)$/i;
+const OPTIMIZABLE_REGEX = /(\.|\/)(jpe?g|png)$/i;
+
/**
* This worker follows a particular promise/callback flow to ensure
* that the media-optimization-worker is installed and has its libraries
@@ -43,20 +47,49 @@ export default class MediaOptimizationWorkerService extends Service {
: true;
let file = data;
- if (!/(\.|\/)(jpe?g|png)$/i.test(file.type)) {
+ const typeOrName = file.type || file.name;
+
+ const isConvertFormat = CONVERT_FORMAT_REGEX.test(typeOrName);
+ const isAnimatedGif = ANIMATED_GIF_REGEX.test(typeOrName);
+ const isOptimizable = OPTIMIZABLE_REGEX.test(typeOrName);
+
+ if (!isConvertFormat && !isAnimatedGif && !isOptimizable) {
return Promise.resolve();
}
+
+ // JXL/HEIC/GIF conversion is gated behind a separate site setting
if (
- file.size <
- this.siteSettings
- .composer_media_optimization_image_bytes_optimization_threshold
+ (isConvertFormat || isAnimatedGif) &&
+ !this.siteSettings.composer_media_optimization_image_convert_enabled
) {
- this.logIfDebug(
- `The file ${file.name} was less than the image optimization bytes threshold (${this.siteSettings.composer_media_optimization_image_bytes_optimization_threshold} bytes), skipping`,
- file
- );
return Promise.resolve();
}
+
+ if (isOptimizable) {
+ if (
+ file.size <
+ this.siteSettings
+ .composer_media_optimization_image_bytes_optimization_threshold
+ ) {
+ this.logIfDebug(
+ `The file ${file.name} was less than the image optimization bytes threshold (${this.siteSettings.composer_media_optimization_image_bytes_optimization_threshold} bytes), skipping`,
+ file
+ );
+ return Promise.resolve();
+ }
+ } else if (isAnimatedGif) {
+ if (
+ file.size <
+ this.siteSettings.composer_media_optimization_gif_conversion_threshold
+ ) {
+ this.logIfDebug(
+ `The GIF ${file.name} was less than the GIF conversion threshold (${this.siteSettings.composer_media_optimization_gif_conversion_threshold} bytes), skipping`,
+ file
+ );
+ return Promise.resolve();
+ }
+ }
+
await this.ensureAvailableWorker();
// eslint-disable-next-line no-async-promise-executor
@@ -66,49 +99,92 @@ export default class MediaOptimizationWorkerService extends Service {
this.currentComposerUploadData = data;
this.promiseResolvers[file.id] = resolve;
- let imageData;
- try {
- imageData = await fileToImageData(file.data, this.capabilities.isIOS);
- } catch (error) {
- this.logIfDebug(error);
- return resolve();
- }
+ const settings = {
+ resize_threshold:
+ this.siteSettings
+ .composer_media_optimization_image_resize_dimensions_threshold,
+ resize_target:
+ this.siteSettings
+ .composer_media_optimization_image_resize_width_target,
+ resize_pre_multiply:
+ this.siteSettings
+ .composer_media_optimization_image_resize_pre_multiply,
+ resize_linear_rgb:
+ this.siteSettings.composer_media_optimization_image_resize_linear_rgb,
+ encode_quality:
+ this.siteSettings.composer_media_optimization_image_encode_quality !==
+ 0
+ ? this.siteSettings.composer_media_optimization_image_encode_quality
+ : this.siteSettings.image_quality,
+ debug_mode: this.siteSettings.composer_media_optimization_debug_mode,
+ mediaOptimizationBundle: this.session.mediaOptimizationBundle,
+ };
+
+ if (isConvertFormat) {
+ let arrayBuffer;
+ try {
+ arrayBuffer = await file.data.arrayBuffer();
+ } catch (error) {
+ this.logIfDebug(error);
+ return resolve();
+ }
- this.worker.postMessage(
- {
- type: "compress",
- fileId: file.id,
- file: imageData.data.buffer,
- fileName: file.name,
- width: imageData.width,
- height: imageData.height,
- originalFileSize: file.size,
- settings: {
- resize_threshold:
- this.siteSettings
- .composer_media_optimization_image_resize_dimensions_threshold,
- resize_target:
- this.siteSettings
- .composer_media_optimization_image_resize_width_target,
- resize_pre_multiply:
- this.siteSettings
- .composer_media_optimization_image_resize_pre_multiply,
- resize_linear_rgb:
- this.siteSettings
- .composer_media_optimization_image_resize_linear_rgb,
- encode_quality:
- this.siteSettings
- .composer_media_optimization_image_encode_quality !== 0
- ? this.siteSettings
- .composer_media_optimization_image_encode_quality
- : this.siteSettings.image_quality,
- debug_mode:
- this.siteSettings.composer_media_optimization_debug_mode,
- mediaOptimizationBundle: this.session.mediaOptimizationBundle,
+ this.worker.postMessage(
+ {
+ type: "convert",
+ fileId: file.id,
+ file: arrayBuffer,
+ fileName: file.name,
+ fileType: file.type || file.data.type,
+ originalFileSize: file.size,
+ settings,
},
- },
- [imageData.data.buffer]
- );
+ [arrayBuffer]
+ );
+ } else if (isAnimatedGif) {
+ let arrayBuffer;
+ try {
+ arrayBuffer = await file.data.arrayBuffer();
+ } catch (error) {
+ this.logIfDebug(error);
+ return resolve();
+ }
+
+ this.worker.postMessage(
+ {
+ type: "convertAnimated",
+ fileId: file.id,
+ file: arrayBuffer,
+ fileName: file.name,
+ originalFileSize: file.size,
+ settings,
+ },
+ [arrayBuffer]
+ );
+ } else {
+ let imageData;
+ try {
+ imageData = await fileToImageData(file.data, this.capabilities.isIOS);
+ } catch (error) {
+ this.logIfDebug(error);
+ return resolve();
+ }
+
+ this.worker.postMessage(
+ {
+ type: "compress",
+ fileId: file.id,
+ file: imageData.data.buffer,
+ fileName: file.name,
+ width: imageData.width,
+ height: imageData.height,
+ originalFileSize: file.size,
+ settings,
+ },
+ [imageData.data.buffer]
+ );
+ }
+
this.workerPendingCount++;
});
}
@@ -179,15 +255,34 @@ export default class MediaOptimizationWorkerService extends Service {
this.workerPendingCount = 0;
}
+ _renameForOutputType(fileName, outputType) {
+ const baseName = fileName.replace(/\.[^.]+$/, "");
+ switch (outputType) {
+ case "image/jpeg":
+ return baseName + ".jpg";
+ case "image/png":
+ return baseName + ".png";
+ case "image/webp":
+ return baseName + ".webp";
+ default:
+ return fileName;
+ }
+ }
+
registerMessageHandler() {
this.worker.onmessage = (workerMessage) => {
switch (workerMessage.data.type) {
case "file":
+ const outputType = workerMessage.data.outputType || "image/jpeg";
+ const outputFileName = this._renameForOutputType(
+ workerMessage.data.fileName,
+ outputType
+ );
const optimizedFile = new File(
[workerMessage.data.file],
- workerMessage.data.fileName,
+ outputFileName,
{
- type: "image/jpeg",
+ type: outputType,
}
);
this.logIfDebug(
@@ -216,6 +311,15 @@ export default class MediaOptimizationWorkerService extends Service {
this.promiseResolvers[workerMessage.data.fileId]();
this.workerPendingCount--;
break;
+ case "skipped":
+ this.logIfDebug(
+ `Conversion skipped for ${workerMessage.data.fileName} (output not smaller than original)`
+ );
+
+ this.promiseResolvers[workerMessage.data.fileId]();
+ this.workerDoneCount++;
+ this.workerPendingCount--;
+ break;
case "installed":
this.logIfDebug("Worker installed");
this.workerInstalled = true;
diff --git a/frontend/discourse/app/static/media-optimization-bundle.js b/frontend/discourse/app/static/media-optimization-bundle.js
index a9122093bac..6cefbce068f 100644
--- a/frontend/discourse/app/static/media-optimization-bundle.js
+++ b/frontend/discourse/app/static/media-optimization-bundle.js
@@ -1,5 +1,12 @@
-import { encode } from "@jsquash/jpeg";
-import resize from "@jsquash/resize";
+import { decodeAnimated as decodeGifAnimated } from "@discourse/gif";
+import { decode as decodeHeic } from "@discourse/heic";
+import { encode as encodeJpeg } from "@discourse/jpeg";
+import { decode as decodeJxl } from "@discourse/jxl";
+import resize from "@discourse/resize";
+import {
+ encode as encodeWebp,
+ encodeAnimated as encodeWebpAnimated,
+} from "@discourse/webp";
function resizeWithAspect(
input_width,
@@ -35,23 +42,18 @@ function logIfDebug(...messages) {
}
}
-globalThis.optimize = async function (
- imageData,
- fileName,
- width,
- height,
- originalFileSize,
- settings
-) {
- // This variable assignemnt is re-written by webpack at build time.
+function setPublicPath(settings) {
+ // This variable assignment is re-written by webpack at build time.
// It ensures that the WASM files are loaded from the CDN, just like this JS entrypoint.
// eslint-disable-next-line no-undef
__webpack_public_path__ = new URL(
`${settings.mediaOptimizationBundle}/../..`,
location.href
).toString();
+}
- const mozJpegDefaultOptions = {
+function buildMozJpegOptions(settings) {
+ return {
quality: settings.encode_quality,
baseline: false,
arithmetic: false,
@@ -69,15 +71,18 @@ globalThis.optimize = async function (
separate_chroma_quality: false,
chroma_quality: 75,
};
+}
- const initialSize = imageData.byteLength;
- logIfDebug(
- `Received imageData ${initialSize} bytes (raw uncompressed pixels) from original file size of ${originalFileSize} bytes (compressed) for ${fileName}`
- );
-
- let maybeResized;
+function hasTransparency(imageData) {
+ for (let i = 3; i < imageData.data.length; i += 4) {
+ if (imageData.data[i] < 255) {
+ return true;
+ }
+ }
+ return false;
+}
- // resize
+async function maybeResize(imageData, width, height, settings) {
if (width > settings.resize_threshold) {
try {
const targetDimensions = resizeWithAspect(
@@ -85,12 +90,7 @@ globalThis.optimize = async function (
height,
settings.resize_target
);
- const wrappedImageData = new ImageData(
- new Uint8ClampedArray(imageData),
- width,
- height
- );
- const resizeResult = await resize(wrappedImageData, {
+ const resizeResult = await resize(imageData, {
width: targetDimensions.width,
height: targetDimensions.height,
method: "lanczos3",
@@ -100,26 +100,55 @@ globalThis.optimize = async function (
if (resizeResult.data[3] !== 255) {
throw "Image corrupted during resize. Falling back to the original for encode";
}
- maybeResized = resizeResult.data;
- width = targetDimensions.width;
- height = targetDimensions.height;
logIfDebug(
- `Post-resizing size for ${fileName} is ${maybeResized.byteLength} bytes (raw uncompressed pixels at ${width}x${height})`
+ `Post-resizing size is ${resizeResult.data.byteLength} bytes (raw uncompressed pixels at ${targetDimensions.width}x${targetDimensions.height})`
);
+ return resizeResult;
} catch (error) {
// eslint-disable-next-line no-console
console.error("Resize failed", error);
- maybeResized = imageData;
+ return imageData;
}
} else {
logIfDebug(`Skipped resize, ${width} < ${settings.resize_threshold}`);
- maybeResized = imageData;
+ return imageData;
}
+}
- // mozJPEG re-encode
- const result = await encode(
- new ImageData(new Uint8ClampedArray(maybeResized), width, height),
- mozJpegDefaultOptions
+globalThis.optimize = async function (
+ imageData,
+ fileName,
+ width,
+ height,
+ originalFileSize,
+ settings
+) {
+ setPublicPath(settings);
+ const mozJpegOptions = buildMozJpegOptions(settings);
+
+ const initialSize = imageData.byteLength;
+ logIfDebug(
+ `Received imageData ${initialSize} bytes (raw uncompressed pixels) from original file size of ${originalFileSize} bytes (compressed) for ${fileName}`
+ );
+
+ const wrappedImageData = new ImageData(
+ new Uint8ClampedArray(imageData),
+ width,
+ height
+ );
+ const resized = await maybeResize(wrappedImageData, width, height, settings);
+ const finalWidth = resized.width;
+ const finalHeight = resized.height;
+
+ const result = await encodeJpeg(
+ resized instanceof ImageData
+ ? resized
+ : new ImageData(
+ new Uint8ClampedArray(resized.data),
+ finalWidth,
+ finalHeight
+ ),
+ mozJpegOptions
);
const finalSize = result.byteLength;
@@ -138,3 +167,98 @@ globalThis.optimize = async function (
return result;
};
+
+globalThis.convert = async function (
+ fileBuffer,
+ fileName,
+ fileType,
+ originalFileSize,
+ settings
+) {
+ setPublicPath(settings);
+
+ logIfDebug(`Converting ${fileName} (${fileType}, ${originalFileSize} bytes)`);
+
+ let imageData;
+ if (/jxl$/i.test(fileType)) {
+ imageData = await decodeJxl(fileBuffer);
+ } else if (/hei[cf]$/i.test(fileType)) {
+ imageData = await decodeHeic(fileBuffer);
+ } else {
+ throw `Unsupported file type for conversion: ${fileType}`;
+ }
+
+ logIfDebug(
+ `Decoded ${fileName} to ${imageData.width}x${imageData.height} ImageData`
+ );
+
+ const transparent = hasTransparency(imageData);
+
+ const resized = await maybeResize(
+ imageData,
+ imageData.width,
+ imageData.height,
+ settings
+ );
+
+ if (transparent) {
+ logIfDebug(
+ `Image ${fileName} has transparency, encoding as WEBP instead of JPEG`
+ );
+ const result = await encodeWebp(resized, {
+ quality: settings.encode_quality,
+ });
+ const finalSize = result.byteLength;
+ logIfDebug(
+ `Converted ${fileName} from ${originalFileSize} bytes to ${finalSize} bytes WEBP`
+ );
+ return { data: result, outputType: "image/webp" };
+ }
+
+ const result = await encodeJpeg(resized, buildMozJpegOptions(settings));
+
+ const finalSize = result.byteLength;
+ logIfDebug(
+ `Converted ${fileName} from ${originalFileSize} bytes to ${finalSize} bytes JPEG (${(originalFileSize / finalSize).toFixed(1)}x compression)`
+ );
+
+ if (finalSize < 20000) {
+ throw "Final size suspiciously small, discarding conversion";
+ }
+
+ return { data: result, outputType: "image/jpeg" };
+};
+
+globalThis.convertAnimated = async function (
+ fileBuffer,
+ fileName,
+ originalFileSize,
+ settings
+) {
+ setPublicPath(settings);
+
+ logIfDebug(
+ `Converting animated ${fileName} (${originalFileSize} bytes) to animated WEBP`
+ );
+
+ const frames = await decodeGifAnimated(fileBuffer);
+ logIfDebug(`Decoded ${frames.length} frames from ${fileName}`);
+
+ const result = await encodeWebpAnimated(frames, {
+ quality: settings.encode_quality,
+ });
+
+ const finalSize = result.byteLength;
+ logIfDebug(
+ `Converted animated ${fileName} from ${originalFileSize} bytes to ${finalSize} bytes WEBP (${(originalFileSize / finalSize).toFixed(1)}x compression)`
+ );
+
+ if (finalSize >= originalFileSize) {
+ logIfDebug(
+ `Animated WEBP (${finalSize} bytes) is not smaller than original GIF (${originalFileSize} bytes), skipping conversion`
+ );
+ return null;
+ }
+
+ return { data: result, outputType: "image/webp" };
+};
diff --git a/frontend/discourse/ember-cli-build.js b/frontend/discourse/ember-cli-build.js
index d486eb75c5f..2d54198ac42 100644
--- a/frontend/discourse/ember-cli-build.js
+++ b/frontend/discourse/ember-cli-build.js
@@ -181,6 +181,7 @@ module.exports = function (defaults) {
entry: {
"assets/media-optimization-bundle.js": {
import: "./static/media-optimization-bundle",
+ chunkLoading: "import-scripts",
runtime: false,
},
},
diff --git a/frontend/discourse/package.json b/frontend/discourse/package.json
index 753813016ab..b64f0688406 100644
--- a/frontend/discourse/package.json
+++ b/frontend/discourse/package.json
@@ -37,8 +37,12 @@
"@glint/template": "^1.7.7",
"@highlightjs/cdn-assets": "11.11.1",
"@json-editor/json-editor": "2.15.2",
- "@jsquash/jpeg": "^1.6.0",
- "@jsquash/resize": "^2.1.0",
+ "@discourse/gif": "^1.0.0",
+ "@discourse/heic": "^1.0.0",
+ "@discourse/jpeg": "^1.0.0",
+ "@discourse/jxl": "^1.0.0",
+ "@discourse/resize": "^2.1.0",
+ "@discourse/webp": "^1.0.0",
"ace-builds": "^1.43.6",
"chart.js": "4.5.1",
"chartjs-adapter-moment": "^1.0.1",
diff --git a/lib/file_helper.rb b/lib/file_helper.rb
index 587cf45bea2..dc82d1e87fa 100644
--- a/lib/file_helper.rb
+++ b/lib/file_helper.rb
@@ -180,7 +180,7 @@ class FileHelper
end
def self.supported_images
- @@supported_images ||= Set.new %w[jpg jpeg png gif svg ico webp avif]
+ @@supported_images ||= Set.new %w[jpg jpeg png gif svg ico webp avif heic heif jxl]
end
def self.inline_images
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4983cb03b81..20a0c27f1b6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -233,6 +233,24 @@ importers:
frontend/discourse:
dependencies:
+ '@discourse/gif':
+ specifier: ^1.0.0
+ version: 1.0.0
+ '@discourse/heic':
+ specifier: ^1.0.0
+ version: 1.0.0
+ '@discourse/jpeg':
+ specifier: ^1.0.0
+ version: 1.6.0
+ '@discourse/jxl':
+ specifier: ^1.0.0
+ version: 1.3.0
+ '@discourse/resize':
+ specifier: ^2.1.0
+ version: 2.1.1
+ '@discourse/webp':
+ specifier: ^1.0.0
+ version: 1.5.0
'@faker-js/faker':
specifier: ^10.4.0
version: 10.4.0
@@ -269,12 +287,6 @@ importers:
'@json-editor/json-editor':
specifier: 2.15.2
version: 2.15.2
- '@jsquash/jpeg':
- specifier: ^1.6.0
- version: 1.6.0
- '@jsquash/resize':
- specifier: ^2.1.0
- version: 2.1.1
ace-builds:
specifier: ^1.43.6
version: 1.43.6
@@ -1731,9 +1743,21 @@ packages:
resolution: {integrity: sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==}
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-hh4EI0yoNWDuPp0CC/8N1NiUcwsCznTXrIefODxHP/c3hE97N9z2RkyKfhINEaTfiWoZx3XyOujDn6L0Pm8nRQ==}
+
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-YMW5o0bHvhL4rjzGt7kpr8geqMEhP7yS20Hh5eMJtDOmHuCqn+icpNLr1ImFygU/yN39MUHVenETXcpDG6PPww==}
+
'@discourse/[email protected]':
resolution: {integrity: sha512-Jn1gdiyHMGUsmUfLFf4Q7VnTAv0l7NePbegU6pKhKHEmbzV3FosGxq30fTOYgVyTS1bxqGjlA6LvQttJpv3ROw==}
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-WrmbizcK3U+J1FcGBfEdW+8tn/aNZxd0g9yEdtKZlsvvkKwq/4sokr1sbdoOPjYIt2M1dmyt6cy+QBxcSnyhrQ==}
+
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-Veu75DEDC7uKsCCsD94UIjFwvHE73+AATBQbBWb83QyJV34wmyxl2Ji+fiiM234mlNn4cpo3DUl0QFrXgRTcfA==}
+
'@discourse/[email protected]':
resolution: {integrity: sha512-VhzVNv13Qw1D9SW7vdFxlTMHbdb93yDsqtcVKcQw5VQM/yuto+qAcAMd3oaLOBR2MjzKOXPMtuhfCAwO1QO4ZQ==}
peerDependencies:
@@ -1742,10 +1766,16 @@ packages:
'@discourse/[email protected]':
resolution: {integrity: sha512-4xr1QWQ0nzmFa2ZXQgWZA+dtE/BU2ePA+qkJWPFzNpq4ZnQi8MmMMAS2285t3rc2ySMBQqYaAArmcSUiufUgRA==}
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-iSPfgyCWTXsLcYoUN7/TxTbCSMlSqCI2v9/dCmg5dQdr/qi0TtRKjMzmSy7+8+Ns2v076IQDtdyfvBT8CQPd3g==}
+
'@discourse/[email protected]':
resolution: {integrity: sha512-7hTABdsykcyG5yzBVbhK28pjqPmOEU4bvC8j7jD118KUVwiqKye7wrJQtEcXICp6yygXE/NpZt410vczw9bURg==}
engines: {node: '>= 20', npm: please-use-pnpm, pnpm: ^10, yarn: please-use-pnpm}
+ '@discourse/[email protected]':
+ resolution: {integrity: sha512-2dXuEED+ISG26RbWij3NvdQmgHCD8ssnPoHMd0LnLKJc/dtd2lqg1dhrrA/WYDxfFoJaoGepoxFOsqe0d2/wqw==}
+
'@ember-compat/[email protected]':
resolution: {integrity: sha512-A1uYo6EZY6CaKeZoXogxtyJCjz2V0+TXxOZCMJFQHHVuMA1DxYqZoZ25juRWIQpR8r77gTnITtYW2uxBg8vGRw==}
engines: {node: 14.* || 16.* || >= 18}
@@ -2572,12 +2602,6 @@ packages:
'@jspreadsheet/[email protected]':
resolution: {integrity: sha512-PDQYf9REQA53I7tVYkvkeyQxrd5jcjUeHgItYnRpjN2QiIQwawSqBDtGGEVQTSboTG+JwgGCuhvOpj7FxeKwew==}
- '@jsquash/[email protected]':
- resolution: {integrity: sha512-zwN46Awh1VM6gXlIcALwb5WzqK5H2e6+Awcs1QP8AvS8ohsK/sbE4esvmH4jhlhW7+CgiUUww66vg0aTnlSIMA==}
-
- '@jsquash/[email protected]':
- resolution: {integrity: sha512-0R5UL1ZLHUT+carjVikcE1QfA+kfNQ2YamYyGVRmhfh4zttU5EY3bQBGxPIPtY2xIAw1P4Kgyxm2xrceRw1r2w==}
-
resolution: {integrity: sha512-WbzE9sdmQtKy8vrNPa9BRnwZh5UF4s1KTmSK0KUVLo3eff5BlQNNWDnFOouNpKfPKDnms9xynJjsMYjMaT/aFQ==}
engines: {node: '>= 18'}
@@ -9182,6 +9206,9 @@ packages:
resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==}
+ resolution: {integrity: sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==}
+
resolution: {integrity: sha512-MrJK9z7kD5Gl3jHBnnBVHvr1saVGAfmkyyrvuNzV/oe0Gr1nwZTy5VSA0Gw2j2Or0Mu8HcjUa44qlBvC2Ofnpg==}
engines: {node: '>= 8'}
@@ -10349,8 +10376,18 @@ snapshots:
enabled: 2.0.0
kuler: 2.0.0
+ '@discourse/[email protected]': {}
+
+ '@discourse/[email protected]': {}
+
'@discourse/[email protected]': {}
+ '@discourse/[email protected]': {}
+
+ '@discourse/[email protected]':
+ dependencies:
+ wasm-feature-detect: 1.8.0
+
dependencies:
'@babel/core': 7.29.0([email protected])
@@ -10384,8 +10421,14 @@ snapshots:
'@discourse/[email protected]': {}
+ '@discourse/[email protected]': {}
+
'@discourse/[email protected]': {}
+ '@discourse/[email protected]':
+ dependencies:
+ wasm-feature-detect: 1.8.0
+
'@ember-compat/[email protected](patch_hash=febdd1f1d24565f6f3be7747fd89cbc86a4476e2836e383610c6bc430436a842)':
dependencies:
'@embroider/addon-shim': 1.10.2
@@ -11341,10 +11384,6 @@ snapshots:
'@jspreadsheet/[email protected]': {}
- '@jsquash/[email protected]': {}
-
- '@jsquash/[email protected]': {}
-
dependencies:
hashery: 1.5.1
@@ -19345,6 +19384,8 @@ snapshots:
dependencies:
makeerror: 1.0.12
+
dependencies:
heimdalljs-logger: 0.1.10
diff --git a/public/javascripts/media-optimization-worker.js b/public/javascripts/media-optimization-worker.js
index a4ed743ef55..1c043562836 100644
--- a/public/javascripts/media-optimization-worker.js
+++ b/public/javascripts/media-optimization-worker.js
@@ -1,3 +1,5 @@
+// The media optimization bundle uses webpack's import-scripts chunk loader,
+// so worker-only dynamic chunks can be loaded without a DOM shim.
onmessage = async function (e) {
switch (e.data.type) {
case "compress":
@@ -31,9 +33,77 @@ onmessage = async function (e) {
});
}
break;
+ case "convert":
+ try {
+ globalThis.debugMode = e.data.settings.debug_mode;
+
+ let converted = await globalThis.convert(
+ e.data.file,
+ e.data.fileName,
+ e.data.fileType,
+ e.data.originalFileSize,
+ e.data.settings
+ );
+ postMessage(
+ {
+ type: "file",
+ file: converted.data,
+ fileName: e.data.fileName,
+ fileId: e.data.fileId,
+ outputType: converted.outputType,
+ },
+ [converted.data]
+ );
+ } catch (error) {
+ console.error(error);
+ postMessage({
+ type: "error",
+ file: e.data.file,
+ fileName: e.data.fileName,
+ fileId: e.data.fileId,
+ });
+ }
+ break;
+ case "convertAnimated":
+ try {
+ globalThis.debugMode = e.data.settings.debug_mode;
+
+ let animatedResult = await globalThis.convertAnimated(
+ e.data.file,
+ e.data.fileName,
+ e.data.originalFileSize,
+ e.data.settings
+ );
+ if (animatedResult) {
+ postMessage(
+ {
+ type: "file",
+ file: animatedResult.data,
+ fileName: e.data.fileName,
+ fileId: e.data.fileId,
+ outputType: animatedResult.outputType,
+ },
+ [animatedResult.data]
+ );
+ } else {
+ postMessage({
+ type: "skipped",
+ fileName: e.data.fileName,
+ fileId: e.data.fileId,
+ });
+ }
+ } 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) {