diff --git a/src/app/aggregate/page.tsx b/src/app/aggregate/page.tsx index 4ea2864..b0a5f03 100644 --- a/src/app/aggregate/page.tsx +++ b/src/app/aggregate/page.tsx @@ -6,20 +6,9 @@ import Image from 'next/image'; import { useRouter, useSearchParams } from 'next/navigation'; import { Suspense, useEffect, useState } from 'react'; -import PageLayout from '@/components/PageLayout'; +import { SearchResult } from '@/lib/types'; -interface SearchResult { - id: string; - title: string; - poster: string; - episodes: string[]; - source: string; - source_name: string; - class?: string; - year: string; - desc?: string; - type_name?: string; -} +import PageLayout from '@/components/PageLayout'; function AggregatePageClient() { const searchParams = useSearchParams(); diff --git a/src/app/api/douban/route.ts b/src/app/api/douban/route.ts index 774e1df..d6871bd 100644 --- a/src/app/api/douban/route.ts +++ b/src/app/api/douban/route.ts @@ -1,18 +1,7 @@ import { NextResponse } from 'next/server'; import { getCacheTime } from '@/lib/config'; - -interface DoubanItem { - title: string; - poster: string; - rate: string; -} - -interface DoubanResponse { - code: number; - message: string; - list: DoubanItem[]; -} +import { DoubanItem, DoubanResult } from '@/lib/types'; interface DoubanApiResponse { subjects: Array<{ @@ -111,7 +100,7 @@ export async function GET(request: Request) { rate: item.rate, })); - const response: DoubanResponse = { + const response: DoubanResult = { code: 200, message: '获取成功', list: list, @@ -181,7 +170,7 @@ function handleTop250(pageStart: number) { }); } - const apiResponse: DoubanResponse = { + const apiResponse: DoubanResult = { code: 200, message: '获取成功', list: movies, diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index f5dc7a0..0b95918 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -1,6 +1,7 @@ import { NextResponse } from 'next/server'; import { API_CONFIG, ApiSite, getApiSites, getCacheTime } from '@/lib/config'; +import { SearchResult } from '@/lib/types'; import { cleanHtmlTags } from '@/lib/utils'; export const runtime = 'edge'; @@ -9,19 +10,6 @@ export const runtime = 'edge'; const MAX_SEARCH_PAGES: number = Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5; -export interface SearchResult { - id: string; - title: string; - poster: string; - episodes: string[]; - source: string; - source_name: string; - class?: string; - year: string; - desc?: string; - type_name?: string; -} - interface ApiSearchItem { vod_id: string; vod_name: string; diff --git a/src/app/douban/page.tsx b/src/app/douban/page.tsx index 0e139b9..86b20a1 100644 --- a/src/app/douban/page.tsx +++ b/src/app/douban/page.tsx @@ -4,24 +4,12 @@ import { useSearchParams } from 'next/navigation'; import { Suspense } from 'react'; import { useEffect, useRef, useState } from 'react'; +import { DoubanItem, DoubanResult } from '@/lib/types'; + import DemoCard from '@/components/DemoCard'; import DoubanCardSkeleton from '@/components/DoubanCardSkeleton'; import PageLayout from '@/components/PageLayout'; -// 定义豆瓣数据项类型 -interface DoubanItem { - title: string; - poster: string; - rate?: string; -} - -// 定义豆瓣响应类型 -interface DoubanResponse { - code: number; - message: string; - list: DoubanItem[]; -} - function DoubanPageClient() { const searchParams = useSearchParams(); const [doubanData, setDoubanData] = useState([]); @@ -65,7 +53,7 @@ function DoubanPageClient() { throw new Error('获取豆瓣数据失败'); } - const data: DoubanResponse = await response.json(); + const data: DoubanResult = await response.json(); if (data.code === 200) { setDoubanData(data.list); @@ -100,7 +88,7 @@ function DoubanPageClient() { throw new Error('获取豆瓣数据失败'); } - const data: DoubanResponse = await response.json(); + const data: DoubanResult = await response.json(); if (data.code === 200) { setDoubanData((prev) => [...prev, ...data.list]); diff --git a/src/app/page.tsx b/src/app/page.tsx index 5c46b89..c0c9137 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,6 +6,7 @@ import { Suspense, useEffect, useState } from 'react'; // 客户端收藏 API import { clearAllFavorites, getAllFavorites } from '@/lib/db.client'; +import { DoubanItem, DoubanResult } from '@/lib/types'; import CapsuleSwitch from '@/components/CapsuleSwitch'; import ContinueWatching from '@/components/ContinueWatching'; @@ -14,18 +15,6 @@ import PageLayout from '@/components/PageLayout'; import ScrollableRow from '@/components/ScrollableRow'; import VideoCard from '@/components/VideoCard'; -interface DoubanItem { - title: string; - poster: string; - rate?: string; -} - -interface DoubanResponse { - code: number; - message: string; - list: DoubanItem[]; -} - function HomeClient() { const [activeTab, setActiveTab] = useState('home'); const [hotMovies, setHotMovies] = useState([]); @@ -56,12 +45,12 @@ function HomeClient() { ]); if (moviesResponse.ok) { - const moviesData: DoubanResponse = await moviesResponse.json(); + const moviesData: DoubanResult = await moviesResponse.json(); setHotMovies(moviesData.list); } if (tvShowsResponse.ok) { - const tvShowsData: DoubanResponse = await tvShowsResponse.json(); + const tvShowsData: DoubanResult = await tvShowsResponse.json(); setHotTvShows(tvShowsData.list); } } finally { diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index 6fc7076..34a0519 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -34,6 +34,7 @@ import { toggleFavorite, } from '@/lib/db.client'; import { type VideoDetail, fetchVideoDetail } from '@/lib/fetchVideoDetail'; +import { SearchResult } from '@/lib/types'; // 扩展 HTMLVideoElement 类型以支持 hls 属性 declare global { @@ -42,17 +43,6 @@ declare global { } } -// 搜索结果类型 -interface SearchResult { - id: string; - title: string; - poster: string; - episodes: string[]; - source: string; - source_name: string; - year: string; -} - function PlayPageClient() { const searchParams = useSearchParams(); // @ts-ignore diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx index 02288bf..d43bae6 100644 --- a/src/app/search/page.tsx +++ b/src/app/search/page.tsx @@ -10,6 +10,7 @@ import { clearSearchHistory, getSearchHistory, } from '@/lib/db.client'; +import { SearchResult } from '@/lib/types'; import AggregateCard from '@/components/AggregateCard'; import PageLayout from '@/components/PageLayout'; @@ -19,20 +20,6 @@ function SearchPageClient() { // 搜索历史 const [searchHistory, setSearchHistory] = useState([]); - // 定义搜索结果类型 - type SearchResult = { - id: string; - title: string; - poster: string; - source: string; - source_name: string; - episodes: string[]; - year: string; - class?: string; - type_name?: string; - desc?: string; - }; - const router = useRouter(); const searchParams = useSearchParams(); const [searchQuery, setSearchQuery] = useState(''); diff --git a/src/lib/types.ts b/src/lib/types.ts index 8c640fb..41f5e28 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -17,3 +17,28 @@ export interface VideoDetail { id: string; }; } + +export interface SearchResult { + id: string; + title: string; + poster: string; + episodes: string[]; + source: string; + source_name: string; + class?: string; + year: string; + desc?: string; + type_name?: string; +} + +export interface DoubanItem { + title: string; + poster: string; + rate: string; +} + +export interface DoubanResult { + code: number; + message: string; + list: DoubanItem[]; +}