// 多平台内容 URL / 嵌入播放器 / 平台名:按 item.platform 分派,替代 V2 抖音写死。 type Item = Record; function str(v: unknown): string | null { if (typeof v === "string" && v.trim()) return v; return null; } // 平台名静态兜底(与 platform_profiles 的 platform_label 对齐)。 // 动态可由 /config/platforms 覆盖;此表保证 catalog 未加载时各处(列表卡、顶栏 chip)仍显示中文。 const PLATFORM_LABELS: Record = { douyin: "抖音", shipinhao: "视频号", kuaishou: "快手", xiaohongshu: "小红书", bilibili: "B站", weixin: "公众号", toutiao: "头条", zhihu: "知乎", youtube: "YouTube", github: "GitHub" }; export function platformLabel(platform: unknown, catalog?: Record): string { const key = String(platform || "").toLowerCase(); return catalog?.[key]?.label || PLATFORM_LABELS[key] || (key ? key : "未知平台"); } // 统一互动指标键 → 中文标签(后端各平台 normalizer 已把原生字段映射到这 5 个键)。 export const HEAT_FIELD_LABELS: Record = { digg_count: "点赞", comment_count: "评论", share_count: "分享", collect_count: "收藏", play_count: "播放" }; // 原帖链接:优先用记录里真实落库的 url;无则仅抖音可由 content_id 拼回,其余平台返回 null(不伪造)。 export function contentUrl(item: Item): string | null { const media = (item.media_record as Item) || {}; const direct = str(item.platform_content_url) || str(item.share_url) || str(item.url) || str(item.aweme_url) || str(media.share_url) || str(item.play_url) || // 视频号无网页原帖,仅有视频流地址,兜底用它 str(media.play_url); if (direct) return direct; const platform = String(item.platform || "").toLowerCase(); const id = str(item.platform_content_id); if (platform === "douyin" && id) { return `https://www.douyin.com/video/${encodeURIComponent(id)}`; } return null; } // 可跨站 iframe 的官方嵌入播放器:仅抖音有(open.douyin.com 无 X-Frame-Options); // 视频号等无公开 embed → null,UI 降级为"打开原帖"。 export function embedPlayerUrl(item: Item): string | null { const platform = String(item.platform || "").toLowerCase(); const id = str(item.platform_content_id); if (platform === "douyin" && id) { return `https://open.douyin.com/player/video?vid=${encodeURIComponent(id)}&autoplay=1`; } return null; }