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 = {
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",

View File

@@ -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 {