import { pickPlayletCardTags, pickVideoCardTags } from "@/components/common/card-tags"; import { playHref } from "@/components/drama-detail/data"; import { formatHeat } from "@/components/ranking/data"; import type { ShortDramaItem } from "@/components/short-drama/data"; import { videoHref } from "@/components/video/video-card"; import type { PlayletHistoryItem, VideoHistoryItem } from "@/lib/api/types"; export const historyTypes = ["短剧", "视频"] as const; export type HistoryType = (typeof historyTypes)[number]; export const HISTORY_PAGE_SIZE = 24; export function formatWatchedAt(value?: string | null) { const raw = (value || "").trim(); if (!raw) return ""; const date = new Date(raw); if (Number.isNaN(date.getTime())) return raw; const pad = (n: number) => String(n).padStart(2, "0"); return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${pad(date.getHours())}:${pad(date.getMinutes())}`; } /** 短剧历史 → 卡片展示(保留接口字段语义,仅做展示文案) */ export function mapPlayletHistoryItem(item: PlayletHistoryItem): ShortDramaItem | null { const id = Number(item.id); if (!Number.isInteger(id) || id < 1) return null; const episode = Number(item.episode) || 0; const href = episode > 0 ? playHref(id, episode, item.slug) : undefined; return { kind: "drama", id: String(id), slug: item.slug, title: (item.title || "").trim() || "未命名短剧", subtitle: (item.desc || "").trim(), tags: pickPlayletCardTags(item), heat: formatHeat(item.heatValue ?? item.countBrowse), episodes: episode > 0 ? `看到第${episode}集` : item.totalEpisode ? `全${item.totalEpisode}集` : "", cover: (item.cover || "").trim(), href, }; } /** 视频历史 → 卡片展示 */ export function mapVideoHistoryItem(item: VideoHistoryItem): ShortDramaItem | null { const id = Number(item.id); if (!Number.isInteger(id) || id < 1) return null; return { kind: "drama", id: String(id), slug: item.slug, title: (item.title || "").trim() || "未命名视频", subtitle: (item.desc || "").trim(), tags: pickVideoCardTags(item), heat: formatHeat(item.watchNum), episodes: formatWatchedAt(item.watchedAt), cover: (item.coverImg || "").trim(), href: videoHref(String(id), item.slug), }; }