From 7b48f9780c54cc8b06e4d93091651e544241d17f Mon Sep 17 00:00:00 2001 From: TerryM Date: Mon, 1 Jun 2026 17:52:33 +0800 Subject: [PATCH] fix: use backend video preview urls --- .../utils/videoPreviewSource.test.ts | 20 ++++++++++++++----- .../messageStream/utils/videoPreviewSource.ts | 6 +++--- src/types/post.ts | 9 +++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/components/messageStream/utils/videoPreviewSource.test.ts b/src/components/messageStream/utils/videoPreviewSource.test.ts index 544d4c9..5b2ad2f 100644 --- a/src/components/messageStream/utils/videoPreviewSource.test.ts +++ b/src/components/messageStream/utils/videoPreviewSource.test.ts @@ -8,8 +8,9 @@ import { const attachment: Attachment = { id: "att-1", kind: "video", - url: "/uploads/desktop-preview.mp4", - mobilePreviewUrl: "/uploads/mobile-540p-preview.mp4", + url: "/uploads/legacy-preview.mp4", + desktopUrl: "/uploads/desktop-preview.mp4", + mobileUrl: "/uploads/mobile-540p-preview.mp4", mime: "video/mp4", filename: "original.mp4", sizeBytes: 1024, @@ -22,18 +23,27 @@ describe("videoPreviewSource", () => { ); }); - it("uses mobilePreviewUrl only when mobile preview is active", () => { + it("uses mobileUrl only when mobile preview is active", () => { expect(videoPreviewSource(attachment, true)).toBe( "/uploads/mobile-540p-preview.mp4", ); }); - it("falls back to the desktop preview when mobilePreviewUrl is absent", () => { + it("falls back to the desktop preview when mobileUrl is absent", () => { expect( - videoPreviewSource({ ...attachment, mobilePreviewUrl: undefined }, true), + videoPreviewSource({ ...attachment, mobileUrl: undefined }, true), ).toBe("/uploads/desktop-preview.mp4"); }); + it("falls back to url when desktopUrl is absent", () => { + expect( + videoPreviewSource( + { ...attachment, desktopUrl: undefined, mobileUrl: undefined }, + false, + ), + ).toBe("/uploads/legacy-preview.mp4"); + }); + it("adds a metadata seek fragment only when the URL has no fragment", () => { expect(videoMetadataPreviewSource("/uploads/video.mp4")).toBe( "/uploads/video.mp4#t=0.1", diff --git a/src/components/messageStream/utils/videoPreviewSource.ts b/src/components/messageStream/utils/videoPreviewSource.ts index 503c1c9..6bd56f9 100644 --- a/src/components/messageStream/utils/videoPreviewSource.ts +++ b/src/components/messageStream/utils/videoPreviewSource.ts @@ -6,10 +6,10 @@ export function videoPreviewSource( attachment: Attachment, useMobilePreview: boolean, ): string { - if (useMobilePreview && attachment.mobilePreviewUrl) { - return attachment.mobilePreviewUrl; + if (useMobilePreview && attachment.mobileUrl) { + return attachment.mobileUrl; } - return attachment.url; + return attachment.desktopUrl || attachment.url; } export function videoMetadataPreviewSource(url: string): string { diff --git a/src/types/post.ts b/src/types/post.ts index f66c1de..e4a065b 100644 --- a/src/types/post.ts +++ b/src/types/post.ts @@ -35,8 +35,13 @@ export type Attachment = { posterUrl?: string; thumbUrl?: string; thumbnailUrl?: string; - /** Optional 540p/mobile-friendly preview video. Downloads still use the original endpoint. */ - mobilePreviewUrl?: string; + /** 1080p/desktop-friendly preview video. Falls back to `url` when absent. */ + desktopUrl?: string; + /** 540p/mobile-friendly preview video. Downloads still use the original endpoint. */ + mobileUrl?: string; + /** Original uploaded video URL, for backend/admin reference only. */ + originUrl?: string; + originSizeBytes?: number; }; /**