mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-22 22:57:35 +08:00
feat: refactor code
This commit is contained in:
@@ -6,20 +6,9 @@ import Image from 'next/image';
|
|||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import { Suspense, useEffect, useState } from 'react';
|
import { Suspense, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import PageLayout from '@/components/PageLayout';
|
import { SearchResult } from '@/lib/types';
|
||||||
|
|
||||||
interface SearchResult {
|
import PageLayout from '@/components/PageLayout';
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
poster: string;
|
|
||||||
episodes: string[];
|
|
||||||
source: string;
|
|
||||||
source_name: string;
|
|
||||||
class?: string;
|
|
||||||
year: string;
|
|
||||||
desc?: string;
|
|
||||||
type_name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function AggregatePageClient() {
|
function AggregatePageClient() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getCacheTime } from '@/lib/config';
|
import { getCacheTime } from '@/lib/config';
|
||||||
|
import { DoubanItem, DoubanResult } from '@/lib/types';
|
||||||
interface DoubanItem {
|
|
||||||
title: string;
|
|
||||||
poster: string;
|
|
||||||
rate: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DoubanResponse {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
list: DoubanItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DoubanApiResponse {
|
interface DoubanApiResponse {
|
||||||
subjects: Array<{
|
subjects: Array<{
|
||||||
@@ -111,7 +100,7 @@ export async function GET(request: Request) {
|
|||||||
rate: item.rate,
|
rate: item.rate,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const response: DoubanResponse = {
|
const response: DoubanResult = {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: '获取成功',
|
message: '获取成功',
|
||||||
list: list,
|
list: list,
|
||||||
@@ -181,7 +170,7 @@ function handleTop250(pageStart: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiResponse: DoubanResponse = {
|
const apiResponse: DoubanResult = {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: '获取成功',
|
message: '获取成功',
|
||||||
list: movies,
|
list: movies,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { API_CONFIG, ApiSite, getApiSites, getCacheTime } from '@/lib/config';
|
import { API_CONFIG, ApiSite, getApiSites, getCacheTime } from '@/lib/config';
|
||||||
|
import { SearchResult } from '@/lib/types';
|
||||||
import { cleanHtmlTags } from '@/lib/utils';
|
import { cleanHtmlTags } from '@/lib/utils';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
@@ -9,19 +10,6 @@ export const runtime = 'edge';
|
|||||||
const MAX_SEARCH_PAGES: number =
|
const MAX_SEARCH_PAGES: number =
|
||||||
Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5;
|
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 {
|
interface ApiSearchItem {
|
||||||
vod_id: string;
|
vod_id: string;
|
||||||
vod_name: string;
|
vod_name: string;
|
||||||
|
|||||||
@@ -4,24 +4,12 @@ import { useSearchParams } from 'next/navigation';
|
|||||||
import { Suspense } from 'react';
|
import { Suspense } from 'react';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
import { DoubanItem, DoubanResult } from '@/lib/types';
|
||||||
|
|
||||||
import DemoCard from '@/components/DemoCard';
|
import DemoCard from '@/components/DemoCard';
|
||||||
import DoubanCardSkeleton from '@/components/DoubanCardSkeleton';
|
import DoubanCardSkeleton from '@/components/DoubanCardSkeleton';
|
||||||
import PageLayout from '@/components/PageLayout';
|
import PageLayout from '@/components/PageLayout';
|
||||||
|
|
||||||
// 定义豆瓣数据项类型
|
|
||||||
interface DoubanItem {
|
|
||||||
title: string;
|
|
||||||
poster: string;
|
|
||||||
rate?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 定义豆瓣响应类型
|
|
||||||
interface DoubanResponse {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
list: DoubanItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function DoubanPageClient() {
|
function DoubanPageClient() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [doubanData, setDoubanData] = useState<DoubanItem[]>([]);
|
const [doubanData, setDoubanData] = useState<DoubanItem[]>([]);
|
||||||
@@ -65,7 +53,7 @@ function DoubanPageClient() {
|
|||||||
throw new Error('获取豆瓣数据失败');
|
throw new Error('获取豆瓣数据失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: DoubanResponse = await response.json();
|
const data: DoubanResult = await response.json();
|
||||||
|
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
setDoubanData(data.list);
|
setDoubanData(data.list);
|
||||||
@@ -100,7 +88,7 @@ function DoubanPageClient() {
|
|||||||
throw new Error('获取豆瓣数据失败');
|
throw new Error('获取豆瓣数据失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: DoubanResponse = await response.json();
|
const data: DoubanResult = await response.json();
|
||||||
|
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
setDoubanData((prev) => [...prev, ...data.list]);
|
setDoubanData((prev) => [...prev, ...data.list]);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Suspense, useEffect, useState } from 'react';
|
|||||||
|
|
||||||
// 客户端收藏 API
|
// 客户端收藏 API
|
||||||
import { clearAllFavorites, getAllFavorites } from '@/lib/db.client';
|
import { clearAllFavorites, getAllFavorites } from '@/lib/db.client';
|
||||||
|
import { DoubanItem, DoubanResult } from '@/lib/types';
|
||||||
|
|
||||||
import CapsuleSwitch from '@/components/CapsuleSwitch';
|
import CapsuleSwitch from '@/components/CapsuleSwitch';
|
||||||
import ContinueWatching from '@/components/ContinueWatching';
|
import ContinueWatching from '@/components/ContinueWatching';
|
||||||
@@ -14,18 +15,6 @@ import PageLayout from '@/components/PageLayout';
|
|||||||
import ScrollableRow from '@/components/ScrollableRow';
|
import ScrollableRow from '@/components/ScrollableRow';
|
||||||
import VideoCard from '@/components/VideoCard';
|
import VideoCard from '@/components/VideoCard';
|
||||||
|
|
||||||
interface DoubanItem {
|
|
||||||
title: string;
|
|
||||||
poster: string;
|
|
||||||
rate?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DoubanResponse {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
list: DoubanItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function HomeClient() {
|
function HomeClient() {
|
||||||
const [activeTab, setActiveTab] = useState('home');
|
const [activeTab, setActiveTab] = useState('home');
|
||||||
const [hotMovies, setHotMovies] = useState<DoubanItem[]>([]);
|
const [hotMovies, setHotMovies] = useState<DoubanItem[]>([]);
|
||||||
@@ -56,12 +45,12 @@ function HomeClient() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (moviesResponse.ok) {
|
if (moviesResponse.ok) {
|
||||||
const moviesData: DoubanResponse = await moviesResponse.json();
|
const moviesData: DoubanResult = await moviesResponse.json();
|
||||||
setHotMovies(moviesData.list);
|
setHotMovies(moviesData.list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tvShowsResponse.ok) {
|
if (tvShowsResponse.ok) {
|
||||||
const tvShowsData: DoubanResponse = await tvShowsResponse.json();
|
const tvShowsData: DoubanResult = await tvShowsResponse.json();
|
||||||
setHotTvShows(tvShowsData.list);
|
setHotTvShows(tvShowsData.list);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
toggleFavorite,
|
toggleFavorite,
|
||||||
} from '@/lib/db.client';
|
} from '@/lib/db.client';
|
||||||
import { type VideoDetail, fetchVideoDetail } from '@/lib/fetchVideoDetail';
|
import { type VideoDetail, fetchVideoDetail } from '@/lib/fetchVideoDetail';
|
||||||
|
import { SearchResult } from '@/lib/types';
|
||||||
|
|
||||||
// 扩展 HTMLVideoElement 类型以支持 hls 属性
|
// 扩展 HTMLVideoElement 类型以支持 hls 属性
|
||||||
declare global {
|
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() {
|
function PlayPageClient() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
clearSearchHistory,
|
clearSearchHistory,
|
||||||
getSearchHistory,
|
getSearchHistory,
|
||||||
} from '@/lib/db.client';
|
} from '@/lib/db.client';
|
||||||
|
import { SearchResult } from '@/lib/types';
|
||||||
|
|
||||||
import AggregateCard from '@/components/AggregateCard';
|
import AggregateCard from '@/components/AggregateCard';
|
||||||
import PageLayout from '@/components/PageLayout';
|
import PageLayout from '@/components/PageLayout';
|
||||||
@@ -19,20 +20,6 @@ function SearchPageClient() {
|
|||||||
// 搜索历史
|
// 搜索历史
|
||||||
const [searchHistory, setSearchHistory] = useState<string[]>([]);
|
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 router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
|||||||
@@ -17,3 +17,28 @@ export interface VideoDetail {
|
|||||||
id: string;
|
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[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user