diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index a1dbb9b..7499228 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -16,7 +16,6 @@ import { savePlayRecord, toggleFavorite, } from '@/lib/db.client'; -import { type VideoDetail } from '@/lib/fetchVideoDetail.client'; import { SearchResult } from '@/lib/types'; import { getVideoResolutionFromM3u8 } from '@/lib/utils'; @@ -43,7 +42,7 @@ function PlayPageClient() { >('searching'); const [loadingMessage, setLoadingMessage] = useState('正在搜索播放源...'); const [error, setError] = useState(null); - const [detail, setDetail] = useState(null); + const [detail, setDetail] = useState(null); // 收藏状态 const [favorited, setFavorited] = useState(false); @@ -90,7 +89,7 @@ function PlayPageClient() { const currentIdRef = useRef(currentId); const videoTitleRef = useRef(videoTitle); const videoYearRef = useRef(videoYear); - const detailRef = useRef(detail); + const detailRef = useRef(detail); const currentEpisodeIndexRef = useRef(currentEpisodeIndex); // 同步最新值到 refs @@ -355,7 +354,7 @@ function PlayPageClient() { // 更新视频地址 const updateVideoUrl = ( - detailData: VideoDetail | null, + detailData: SearchResult | null, episodeIndex: number ) => { if ( diff --git a/src/lib/fetchVideoDetail.client.ts b/src/lib/fetchVideoDetail.client.ts deleted file mode 100644 index 16104b0..0000000 --- a/src/lib/fetchVideoDetail.client.ts +++ /dev/null @@ -1,72 +0,0 @@ -export interface VideoDetail { - id: string; - title: string; - poster: string; - episodes: string[]; - source: string; - source_name: string; - class?: string; - year: string; - desc?: string; - type_name?: string; - douban_id?: number; -} - -interface FetchVideoDetailOptions { - source: string; - id: string; - fallbackTitle?: string; -} - -/** - * 根据 source 与 id 获取视频详情。 - * 1. 若传入 fallbackTitle,则先调用 /api/search 搜索精确匹配。 - * 2. 若搜索未命中或未提供 fallbackTitle,则直接调用 /api/detail。 - */ -export async function fetchVideoDetail({ - source, - id, - fallbackTitle = '', -}: FetchVideoDetailOptions): Promise { - // 优先通过搜索接口查找精确匹配 - if (fallbackTitle) { - try { - const searchResp = await fetch( - `/api/search?q=${encodeURIComponent(fallbackTitle.trim())}` - ); - if (searchResp.ok) { - const searchData = await searchResp.json(); - const exactMatch = searchData.results.find( - (item: VideoDetail) => - item.source.toString() === source.toString() && - item.id.toString() === id.toString() - ); - if (exactMatch) { - return exactMatch as VideoDetail; - } - } - } catch (error) { - // do nothing - } - } - - // 调用 /api/detail 接口 - const response = await fetch(`/api/detail?source=${source}&id=${id}`); - if (!response.ok) { - throw new Error('获取详情失败'); - } - const data = await response.json(); - - return { - id: data?.videoInfo?.id || id, - title: data?.videoInfo?.title.trim() || fallbackTitle.trim(), - poster: data?.videoInfo?.cover || '', - episodes: data?.episodes || [], - source: data?.videoInfo?.source || source, - source_name: data?.videoInfo?.source_name || '', - class: data?.videoInfo?.remarks || '', - year: data?.videoInfo?.year || 'unknown', - desc: data?.videoInfo?.desc || '', - type_name: data?.videoInfo?.type || '', - } as VideoDetail; -} diff --git a/src/lib/fetchVideoDetail.ts b/src/lib/fetchVideoDetail.ts index 2dbd075..4dafcde 100644 --- a/src/lib/fetchVideoDetail.ts +++ b/src/lib/fetchVideoDetail.ts @@ -71,15 +71,15 @@ export async function fetchVideoDetail({ const detail = await getDetailFromApi(apiSite, id); return { - id: detail.videoInfo.id, - title: detail.videoInfo.title, - poster: detail.videoInfo.cover || '', + id: detail.id, + title: detail.title, + poster: detail.poster || '', episodes: detail.episodes, - source: detail.videoInfo.source, - source_name: detail.videoInfo.source_name, - class: detail.videoInfo.remarks, - year: detail.videoInfo.year || '', - desc: detail.videoInfo.desc, - type_name: detail.videoInfo.type, + source: detail.source, + source_name: detail.source_name, + class: detail.class, + year: detail.year || '', + desc: detail.desc, + type_name: detail.type_name, }; }