mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-21 17:24:41 +08:00
fix: same SearchResult
This commit is contained in:
@@ -3,20 +3,6 @@ import { SearchResult } from '@/lib/types';
|
||||
|
||||
import { getDetailFromApi, searchFromApi } from './downstream';
|
||||
|
||||
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;
|
||||
@@ -32,7 +18,7 @@ export async function fetchVideoDetail({
|
||||
source,
|
||||
id,
|
||||
fallbackTitle = '',
|
||||
}: FetchVideoDetailOptions): Promise<VideoDetail> {
|
||||
}: FetchVideoDetailOptions): Promise<SearchResult> {
|
||||
// 优先通过搜索接口查找精确匹配
|
||||
const apiSites = getAvailableApiSites();
|
||||
const apiSite = apiSites.find((site) => site.key === source);
|
||||
@@ -48,19 +34,7 @@ export async function fetchVideoDetail({
|
||||
item.id.toString() === id.toString()
|
||||
);
|
||||
if (exactMatch) {
|
||||
return {
|
||||
id: exactMatch.id,
|
||||
title: exactMatch.title,
|
||||
poster: exactMatch.poster,
|
||||
episodes: exactMatch.episodes,
|
||||
source: exactMatch.source,
|
||||
source_name: exactMatch.source_name,
|
||||
class: exactMatch.class,
|
||||
year: exactMatch.year,
|
||||
desc: exactMatch.desc,
|
||||
type_name: exactMatch.type_name,
|
||||
douban_id: exactMatch.douban_id,
|
||||
} as VideoDetail;
|
||||
return exactMatch;
|
||||
}
|
||||
} catch (error) {
|
||||
// do nothing
|
||||
@@ -69,17 +43,9 @@ export async function fetchVideoDetail({
|
||||
|
||||
// 调用 /api/detail 接口
|
||||
const detail = await getDetailFromApi(apiSite, id);
|
||||
if (!detail) {
|
||||
throw new Error('获取视频详情失败');
|
||||
}
|
||||
|
||||
return {
|
||||
id: detail.id,
|
||||
title: detail.title,
|
||||
poster: detail.poster || '',
|
||||
episodes: detail.episodes,
|
||||
source: detail.source,
|
||||
source_name: detail.source_name,
|
||||
class: detail.class,
|
||||
year: detail.year || '',
|
||||
desc: detail.desc,
|
||||
type_name: detail.type_name,
|
||||
};
|
||||
return detail;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import { db } from '@/lib/db';
|
||||
import { type VideoDetail, fetchVideoDetail } from '@/lib/fetchVideoDetail';
|
||||
import { fetchVideoDetail } from '@/lib/fetchVideoDetail';
|
||||
import { SearchResult } from '@/lib/types';
|
||||
|
||||
const STORAGE_TYPE = process.env.NEXT_PUBLIC_STORAGE_TYPE ?? 'localstorage';
|
||||
|
||||
@@ -16,14 +17,14 @@ async function refreshRecordAndFavorites() {
|
||||
users.push(process.env.USERNAME);
|
||||
}
|
||||
// 函数级缓存:key 为 `${source}+${id}`,值为 Promise<VideoDetail | null>
|
||||
const detailCache = new Map<string, Promise<VideoDetail | null>>();
|
||||
const detailCache = new Map<string, Promise<SearchResult | null>>();
|
||||
|
||||
// 获取详情 Promise(带缓存和错误处理)
|
||||
const getDetail = async (
|
||||
source: string,
|
||||
id: string,
|
||||
fallbackTitle: string
|
||||
): Promise<VideoDetail | null> => {
|
||||
): Promise<SearchResult | null> => {
|
||||
const key = `${source}+${id}`;
|
||||
let promise = detailCache.get(key);
|
||||
if (!promise) {
|
||||
|
||||
Reference in New Issue
Block a user