Client-side optimization pipeline with apply-to-J-ID

Backend:
- POST /api/files/J-x/optimize/ applies a browser-processed file: replaces
  every copy (renaming when the extension changes), recomputes MD5, size
  and perceptual hashes, seeds guest visibility; 400 when identical,
  409 when the result matches another item, owner/staff only.

Frontend (no server-side processing by design):
- optimize.worker.ts + pipelines: Mediabunny/WebCodecs for video with a
  prefer-hardware hint and per-browser codec detection; MozJPEG/OxiPNG/
  libwebp (jSquash) for images; gifuct-js+gifenc and UPNG for GIF/APNG.
- OptimizeModal: per-file-type options, original vs processed previews
  with sizes/savings, progress bar with ETA, then Apply (overwrite).
- Optimize button on the library detail for the uploader/staff.
This commit is contained in:
2026-09-17 20:03:22 -05:00
parent 90e61bb333
commit bab9904fc8
14 changed files with 1721 additions and 8 deletions
+15 -5
View File
@@ -101,9 +101,18 @@ Files now stage first and are resolved before entering the library.
## 4. Staff tools
- [ ] **Optimization modal** (image quality, GIF/APNG resolution+FPS+compression,
video bitrate/presets/two-pass/hw-accel) with original vs processed preview
and override
- [x] **Optimization modal** (client-side, no server processing)
- [x] Browser pipeline in a Web Worker: Mediabunny/WebCodecs for video
(hardware-accelerated where available), jSquash (MozJPEG/OxiPNG/libwebp)
for images, gifenc/gifuct-js + UPNG for GIF/APNG
- [x] Options per file type: image quality/resolution; animation
scale/fps/palette; video quality/resolution/codec/container/hardware
preference (codec support detected per browser)
- [x] Original vs processed previews with sizes and savings, progress bar
with ETA and a "Processing the file…" state
- [x] Apply overwrites the same J-ID: `POST /api/files/J-x/optimize/` replaces
the file(s) and recomputes MD5/size/perceptual hashes (409 when the
result matches another item, 400 when it is identical)
- [ ] **Stats dashboard**
- [ ] CPU / RAM / GPU / disk usage
- [ ] Active jobs list (this is what makes the footer "Active Workers" real)
@@ -139,8 +148,9 @@ Files now stage first and are resolved before entering the library.
- Duplicates and upload visual-similarity share the perceptual hashing layer
(`imagehash` server-side; no external hashing service).
- Download progress, optimization jobs and the stats "Active Workers" count all
want the same background-task/progress primitive — design it once.
- Download progress, optimization and the stats "Active Workers" count share
the same task style; optimization itself runs in the browser (the home
server is too weak for ffmpeg) and only the result is uploaded.
- IQDB and e621 matching depend on e621 credentials being configured; the SPA
talks to e621 directly for browsing, while the backend e621 client
(`apps/library/e621.py`) handles metadata matching and batch scans.