feat: refactor code

This commit is contained in:
shinya
2025-06-29 20:36:03 +08:00
parent 0b0048209f
commit 5c8360d9dd
8 changed files with 40 additions and 95 deletions

View File

@@ -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();

View File

@@ -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,

View File

@@ -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;

View File

@@ -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<DoubanItem[]>([]);
@@ -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]);

View File

@@ -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<DoubanItem[]>([]);
@@ -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 {

View File

@@ -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

View File

@@ -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<string[]>([]);
// 定义搜索结果类型
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('');

View File

@@ -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[];
}