fix: use backend video preview urls
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 37s

This commit is contained in:
TerryM
2026-06-01 17:52:33 +08:00
parent b4eb44f824
commit 7b48f9780c
3 changed files with 25 additions and 10 deletions

View File

@@ -8,8 +8,9 @@ import {
const attachment: Attachment = { const attachment: Attachment = {
id: "att-1", id: "att-1",
kind: "video", kind: "video",
url: "/uploads/desktop-preview.mp4", url: "/uploads/legacy-preview.mp4",
mobilePreviewUrl: "/uploads/mobile-540p-preview.mp4", desktopUrl: "/uploads/desktop-preview.mp4",
mobileUrl: "/uploads/mobile-540p-preview.mp4",
mime: "video/mp4", mime: "video/mp4",
filename: "original.mp4", filename: "original.mp4",
sizeBytes: 1024, 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( expect(videoPreviewSource(attachment, true)).toBe(
"/uploads/mobile-540p-preview.mp4", "/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( expect(
videoPreviewSource({ ...attachment, mobilePreviewUrl: undefined }, true), videoPreviewSource({ ...attachment, mobileUrl: undefined }, true),
).toBe("/uploads/desktop-preview.mp4"); ).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", () => { it("adds a metadata seek fragment only when the URL has no fragment", () => {
expect(videoMetadataPreviewSource("/uploads/video.mp4")).toBe( expect(videoMetadataPreviewSource("/uploads/video.mp4")).toBe(
"/uploads/video.mp4#t=0.1", "/uploads/video.mp4#t=0.1",

View File

@@ -6,10 +6,10 @@ export function videoPreviewSource(
attachment: Attachment, attachment: Attachment,
useMobilePreview: boolean, useMobilePreview: boolean,
): string { ): string {
if (useMobilePreview && attachment.mobilePreviewUrl) { if (useMobilePreview && attachment.mobileUrl) {
return attachment.mobilePreviewUrl; return attachment.mobileUrl;
} }
return attachment.url; return attachment.desktopUrl || attachment.url;
} }
export function videoMetadataPreviewSource(url: string): string { export function videoMetadataPreviewSource(url: string): string {

View File

@@ -35,8 +35,13 @@ export type Attachment = {
posterUrl?: string; posterUrl?: string;
thumbUrl?: string; thumbUrl?: string;
thumbnailUrl?: string; thumbnailUrl?: string;
/** Optional 540p/mobile-friendly preview video. Downloads still use the original endpoint. */ /** 1080p/desktop-friendly preview video. Falls back to `url` when absent. */
mobilePreviewUrl?: string; 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;
}; };
/** /**