文件
tennis-training-hub/server/tutorialImageCatalog.ts
2026-03-15 12:01:21 +08:00

70 行
2.4 KiB
TypeScript

export type TutorialImageSpec = {
imageUrl: string;
sourcePageUrl: string;
sourceLabel: string;
};
export const TUTORIAL_IMAGE_LIBRARY = {
forehand: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/0/00/Ray_Dunlop_forehand.jpg",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Ray_Dunlop_forehand.jpg",
sourceLabel: "Wikimedia Commons",
},
backhand: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/8/8c/Backhand_Federer.jpg",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Backhand_Federer.jpg",
sourceLabel: "Wikimedia Commons",
},
serve: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/8/85/Serena_Williams_Serves.JPG",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Serena_Williams_Serves.JPG",
sourceLabel: "Wikimedia Commons",
},
volley: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/a/af/Ernest_w._lewis%2C_volleying.jpg",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Ernest_w._lewis,_volleying.jpg",
sourceLabel: "Wikimedia Commons",
},
action: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/3/34/Frances_Tiafoe_Backhand.jpg",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Frances_Tiafoe_Backhand.jpg",
sourceLabel: "Wikimedia Commons",
},
wall: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/2/2c/Tennis_wall.jpg",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Tennis_wall.jpg",
sourceLabel: "Wikimedia Commons",
},
strategy: {
imageUrl: "https://upload.wikimedia.org/wikipedia/commons/f/f3/Court_plan.png",
sourcePageUrl: "https://commons.wikimedia.org/wiki/File:Court_plan.png",
sourceLabel: "Wikimedia Commons",
},
} satisfies Record<string, TutorialImageSpec>;
const CATEGORY_TO_IMAGE: Record<string, keyof typeof TUTORIAL_IMAGE_LIBRARY> = {
forehand: "forehand",
backhand: "backhand",
serve: "serve",
volley: "volley",
footwork: "action",
shadow: "forehand",
wall: "wall",
fitness: "action",
strategy: "strategy",
};
export function buildTutorialImageKey(slug: string) {
return `tutorials/${slug}.webp`;
}
export function buildTutorialImageUrl(slug: string) {
return `/uploads/${buildTutorialImageKey(slug)}`;
}
export function getTutorialImageSpec(category: string): TutorialImageSpec | null {
const imageKey = CATEGORY_TO_IMAGE[category];
if (!imageKey) return null;
return TUTORIAL_IMAGE_LIBRARY[imageKey];
}