web: EXPORT offers a size, and a bigger one is upscaled in the browser

The server still never sees a photo, so the model has to run in the page.
Real-ESRGAN x4v3 ships as a 4.9MB ONNX in public/models and is loaded
lazily on the first export that actually needs it; the wasm runtime is
copied next to CanvasKit at build time and stays lazily fetched, cached
for 30 days. Vite is told onnxruntime-web is external-wasm so no 28MB
asset lands in the bundle.

UNCHANGED keeps the old path and the tier cap; 2K/4K/custom upscale only
when the request is larger than the photo being edited, otherwise they
resize down. Guests keep UNCHANGED and 2K. Tiling is 256px with an 8px
overlap, so memory follows the target size rather than four times it.
This commit is contained in:
2026-09-22 09:40:18 +07:00
parent f9a40a9e1c
commit c0c99a9672
13 changed files with 17553 additions and 22 deletions
+26 -11
View File
@@ -1,16 +1,31 @@
// canvaskit-wasm resolves its wasm at runtime, not through the bundler, so the
// binary has to be a served asset. 8MB in the repo is worse than 8MB copied out
// of node_modules at build time (the Docker build stage does the same).
// canvaskit and onnxruntime resolve their wasm at runtime, not through the
// bundler, so the binaries have to be served assets. 20MB of wasm in the repo is
// worse than 20MB copied out of node_modules at build time (the Docker build
// stage does the same).
import { copyFileSync, mkdirSync, existsSync } from 'node:fs';
import { dirname } from 'node:path';
const from = 'node_modules/canvaskit-wasm/bin/full/canvaskit.wasm';
const to = 'public/wasm/canvaskit.wasm';
const copies = [
['node_modules/canvaskit-wasm/bin/full/canvaskit.wasm', 'public/wasm/canvaskit.wasm'],
// onnxruntime-web's default entry (its own bundled glue) looks for the jsep
// build of the runtime in `env.wasm.wasmPaths`; that build carries both the
// WebGPU and the plain WebAssembly execution provider, so one file is enough.
[
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm',
'public/wasm/ort/ort-wasm-simd-threaded.jsep.wasm',
],
[
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.mjs',
'public/wasm/ort/ort-wasm-simd-threaded.jsep.mjs',
],
];
if (!existsSync(from)) {
console.error(`missing ${from} — run npm install first`);
process.exit(1);
for (const [from, to] of copies) {
if (!existsSync(from)) {
console.error(`missing ${from} — run npm install first`);
process.exit(1);
}
mkdirSync(dirname(to), { recursive: true });
copyFileSync(from, to);
console.log(`copied ${from} -> ${to}`);
}
mkdirSync(dirname(to), { recursive: true });
copyFileSync(from, to);
console.log(`copied ${from} -> ${to}`);