Add optimized tutorial cover images
这个提交包含在:
43
server/tutorialImages.test.ts
普通文件
43
server/tutorialImages.test.ts
普通文件
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildTutorialImageFfmpegArgs,
|
||||
buildTutorialImageKey,
|
||||
buildTutorialImageUrl,
|
||||
getTutorialImageSpec,
|
||||
} from "./tutorialImages";
|
||||
|
||||
describe("tutorialImages", () => {
|
||||
it("maps tennis categories to image specs", () => {
|
||||
expect(getTutorialImageSpec("forehand")?.sourcePageUrl).toContain("Ray_Dunlop_forehand");
|
||||
expect(getTutorialImageSpec("backhand")?.sourcePageUrl).toContain("Backhand_Federer");
|
||||
expect(getTutorialImageSpec("serve")?.sourcePageUrl).toContain("Serena_Williams_Serves");
|
||||
expect(getTutorialImageSpec("wall")?.sourcePageUrl).toContain("Tennis_wall");
|
||||
expect(getTutorialImageSpec("unknown")).toBeNull();
|
||||
});
|
||||
|
||||
it("builds stable storage keys and public URLs", () => {
|
||||
expect(buildTutorialImageKey("forehand-fundamentals")).toBe("tutorials/forehand-fundamentals.webp");
|
||||
expect(buildTutorialImageUrl("forehand-fundamentals")).toBe("/uploads/tutorials/forehand-fundamentals.webp");
|
||||
});
|
||||
|
||||
it("uses a fixed compression pipeline for tutorial images", () => {
|
||||
const args = buildTutorialImageFfmpegArgs("/tmp/input.jpg", "/tmp/output.webp");
|
||||
|
||||
expect(args).toEqual([
|
||||
"-y",
|
||||
"-i",
|
||||
"/tmp/input.jpg",
|
||||
"-vf",
|
||||
"scale=1200:675:force_original_aspect_ratio=increase,crop=1200:675",
|
||||
"-frames:v",
|
||||
"1",
|
||||
"-c:v",
|
||||
"libwebp",
|
||||
"-quality",
|
||||
"78",
|
||||
"-compression_level",
|
||||
"6",
|
||||
"/tmp/output.webp",
|
||||
]);
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户