feat(webui): remove original-file display fallbacks, use proxies only (#273)

* feat(webui): remove original-file display fallbacks, use proxies only

WebUI now never uses the raw original file for display. All viewers
(image, video, compare, pdf) render exclusively from transcoded proxies;
when no proxy exists the viewer shows an unavailable placeholder instead
of falling back to media.original.

- getBestTranscode: drop the isRaw fallback candidates
- video-viewer / compare-video-pane: remove the synthetic 'Original'
  resolution entry and the original.downloadUrl hasMedia gate
- image-viewer / compare-image-pane: remove original.downloadUrl default
- pdf-viewer: require pdfTranscode.url (no original fallback)
- download menus (video-control-bar, breadcrumb-nav): use
  media.original.key for the 'Original' download option instead of the
  isRaw transcode marker entry

Backend:
- transcode-video workflow no longer pushes the isRaw:true marker entry
  into videoTranscodes (it pointed at the original file key)
- remove media.original.downloadUrl from the DTO, asset service mapping,
  MediaInfo DB type, and transcode workflows/activities (it was only
  consumed by the removed display fallbacks; downloads already use key
  via the download-url endpoints)

Tests/fixtures updated; docs updated to state the proxy-only display
policy.

* refactor: remove isRaw field via data migration, clean legacy media JSON

Add a Prisma data migration that cleans legacy media JSONB on both
assets and watermark_files:
- drop the raw-original marker entries (isRaw: true) from
  videoTranscodes / imageTranscodes — they pointed at the original file
  key and were only used by the removed display fallbacks / download
  menus, which now use media.original.key directly
- strip the isRaw field from remaining transcode entries
- drop original.downloadUrl (removed from the AssetInfo DTO)

The migration is generated via prisma migrate dev --create-only and
applied automatically by migrate deploy in production. It is guarded by
a test (packages/db/src/clean-media-migration.test.ts) that seeds legacy
media JSON, runs the migration SQL, and asserts the transform on both
tables.

With the data cleaned, remove the isRaw field entirely from the codebase:
- DTO schemas + ImageTranscode/VideoTranscode interfaces
- PrismaJson MediaInfo transcode types
- watermark activity isRaw skip (and its test), watermark proxy mapping,
  agent-embedding transcode selection, webui transcode filters, and all
  test fixtures

AGENTS.md: clarify that the no-manual-migration rule applies to DDL;
data migrations (pure SQL transforms, no schema change) are allowed
inside a --create-only generated migration and must be tested.
This commit is contained in:
Yiling-J
2026-08-07 22:40:06 +08:00
committed by GitHub
parent 03aea2cb36
commit 624a3a6a54
31 changed files with 277 additions and 315 deletions
@@ -0,0 +1,86 @@
-- Data cleanup: remove legacy media JSON fields that are no longer used.
--
-- WebUI now displays transcoded proxies only and never falls back to the raw
-- original file:
-- 1. Drop the raw-original marker entries (`isRaw: true`) from
-- videoTranscodes / imageTranscodes. They pointed at the original file
-- key and were only consumed by the removed display fallbacks and the
-- download-menu entries, which now use media.original.key directly.
-- 2. Strip the now-removed `isRaw` field from remaining transcode entries.
-- 3. Drop `original.downloadUrl` (removed from the AssetInfo DTO; downloads
-- resolve a fresh presigned URL from `key` via the download-url APIs).
UPDATE "assets"
SET "media" = jsonb_set(
jsonb_set(
CASE WHEN jsonb_typeof("media"->'original') = 'object'
THEN "media" #- '{original,downloadUrl}'
ELSE "media" END,
'{videoTranscodes}',
COALESCE(
(SELECT jsonb_agg(elem - 'isRaw')
FROM jsonb_array_elements("media"->'videoTranscodes') elem
WHERE jsonb_typeof(elem) = 'object'
AND NOT COALESCE((elem->>'isRaw')::boolean, false)),
'[]'::jsonb
)
),
'{imageTranscodes}',
COALESCE(
(SELECT jsonb_agg(elem - 'isRaw')
FROM jsonb_array_elements("media"->'imageTranscodes') elem
WHERE jsonb_typeof(elem) = 'object'
AND NOT COALESCE((elem->>'isRaw')::boolean, false)),
'[]'::jsonb
)
)
WHERE "media" IS NOT NULL
AND (
(jsonb_typeof("media"->'original') = 'object' AND "media"->'original' ? 'downloadUrl')
OR EXISTS (
SELECT 1 FROM jsonb_array_elements(COALESCE("media"->'videoTranscodes', '[]'::jsonb)) e
WHERE jsonb_typeof(e) = 'object' AND e ? 'isRaw'
)
OR EXISTS (
SELECT 1 FROM jsonb_array_elements(COALESCE("media"->'imageTranscodes', '[]'::jsonb)) e
WHERE jsonb_typeof(e) = 'object' AND e ? 'isRaw'
)
);
-- Same cleanup for watermarked proxy media.
UPDATE "watermark_files"
SET "media" = jsonb_set(
jsonb_set(
CASE WHEN jsonb_typeof("media"->'original') = 'object'
THEN "media" #- '{original,downloadUrl}'
ELSE "media" END,
'{videoTranscodes}',
COALESCE(
(SELECT jsonb_agg(elem - 'isRaw')
FROM jsonb_array_elements("media"->'videoTranscodes') elem
WHERE jsonb_typeof(elem) = 'object'
AND NOT COALESCE((elem->>'isRaw')::boolean, false)),
'[]'::jsonb
)
),
'{imageTranscodes}',
COALESCE(
(SELECT jsonb_agg(elem - 'isRaw')
FROM jsonb_array_elements("media"->'imageTranscodes') elem
WHERE jsonb_typeof(elem) = 'object'
AND NOT COALESCE((elem->>'isRaw')::boolean, false)),
'[]'::jsonb
)
)
WHERE "media" IS NOT NULL
AND (
(jsonb_typeof("media"->'original') = 'object' AND "media"->'original' ? 'downloadUrl')
OR EXISTS (
SELECT 1 FROM jsonb_array_elements(COALESCE("media"->'videoTranscodes', '[]'::jsonb)) e
WHERE jsonb_typeof(e) = 'object' AND e ? 'isRaw'
)
OR EXISTS (
SELECT 1 FROM jsonb_array_elements(COALESCE("media"->'imageTranscodes', '[]'::jsonb)) e
WHERE jsonb_typeof(e) = 'object' AND e ? 'isRaw'
)
);
-3
View File
@@ -74,7 +74,6 @@ declare global {
width: number
height: number
resolution?: string
isRaw?: boolean
}
export interface ImageTranscode {
@@ -84,7 +83,6 @@ declare global {
height: number
quality: number
format: string
isRaw?: boolean
}
export interface SpriteInfo {
@@ -117,7 +115,6 @@ declare global {
export interface OriginalInfo {
key: string
downloadUrl: string
filesizeInBytes: number
codec: string
}