From b61865fb49a9bf264cf67a05c9ce7234bc5aaa6b Mon Sep 17 00:00:00 2001 From: mtvpls Date: Thu, 19 Mar 2026 16:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E9=A2=91=E6=9D=83?= =?UTF-8?q?=E9=87=8D=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/search/route.ts | 11 +++++++++-- src/app/api/search/ws/route.ts | 7 +++++++ src/app/play/page.tsx | 22 +++------------------- src/lib/types.ts | 1 + 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 0630ee4..0f6b89c 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -83,6 +83,7 @@ export async function GET(request: NextRequest) { id: item.Id, source: sourceValue, source_name: sourceName, + weight: weightMap.get(sourceValue) ?? 0, title: item.Name, poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined), episodes: [], @@ -138,6 +139,7 @@ export async function GET(request: NextRequest) { id: folderName, source: 'openlist', source_name: '私人影库', + weight: weightMap.get('openlist') ?? 0, title: info.title, poster: getTMDBImageUrl(info.poster_path), episodes: [], @@ -195,6 +197,11 @@ export async function GET(request: NextRequest) { let flattenedResults = [...openlistResults, ...embyResults, ...apiResultsFlat]; + flattenedResults = flattenedResults.map((result) => ({ + ...result, + weight: result.weight ?? (weightMap.get(result.source) ?? 0), + })); + if (!config.SiteConfig.DisableYellowFilter) { flattenedResults = flattenedResults.filter((result) => { const typeName = result.type_name || ''; @@ -204,8 +211,8 @@ export async function GET(request: NextRequest) { // 按权重降序排序 flattenedResults.sort((a, b) => { - const weightA = weightMap.get(a.source) ?? 0; - const weightB = weightMap.get(b.source) ?? 0; + const weightA = a.weight ?? 0; + const weightB = b.weight ?? 0; return weightB - weightA; }); diff --git a/src/app/api/search/ws/route.ts b/src/app/api/search/ws/route.ts index 14aed20..b3ea9f8 100644 --- a/src/app/api/search/ws/route.ts +++ b/src/app/api/search/ws/route.ts @@ -147,6 +147,7 @@ export async function GET(request: NextRequest) { id: item.Id, source: sourceValue, source_name: sourceName, + weight: weightMap.get(sourceValue) ?? 0, title: item.Name, poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined), episodes: [], @@ -253,6 +254,7 @@ export async function GET(request: NextRequest) { id: key, source: 'openlist', source_name: '私人影库', + weight: weightMap.get('openlist') ?? 0, title: info.title, poster: getTMDBImageUrl(info.poster_path), episodes: [], @@ -335,6 +337,11 @@ export async function GET(request: NextRequest) { }); } + filteredResults = filteredResults.map((result) => ({ + ...result, + weight: result.weight ?? (weightMap.get(result.source) ?? 0), + })); + // 发送该源的搜索结果 completedSources++; diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index 68c2df7..c8999fb 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -1504,22 +1504,6 @@ function PlayPageClient() { ): Promise => { if (sources.length === 1) return sources[0]; - // 获取配置以获取权重信息 - let weightMap = new Map(); - try { - const configResponse = await fetch('/api/admin/config'); - if (configResponse.ok) { - const configData = await configResponse.json(); - if (configData.Config?.SourceConfig) { - configData.Config.SourceConfig.forEach((source: any) => { - weightMap.set(source.key, source.weight ?? 0); - }); - } - } - } catch (error) { - console.warn('获取配置失败,权重将使用默认值0:', error); - } - // 将播放源均分为两批,并发测速各批,避免一次性过多请求 const batchSize = Math.ceil(sources.length / 2); const allResults: Array<{ @@ -1602,8 +1586,8 @@ function PlayPageClient() { if (successfulResults.length === 0) { console.warn('所有播放源测速都失败,按权重排序'); const sortedByWeight = [...sources].sort((a, b) => { - const weightA = weightMap.get(a.source) ?? 0; - const weightB = weightMap.get(b.source) ?? 0; + const weightA = a.weight ?? 0; + const weightB = b.weight ?? 0; return weightB - weightA; }); return sortedByWeight[0]; @@ -1642,7 +1626,7 @@ function PlayPageClient() { maxSpeed, minPing, maxPing, - weightMap.get(result.source.source) ?? 0 + result.source.weight ?? 0 ), })); diff --git a/src/lib/types.ts b/src/lib/types.ts index e08c0a5..562bddb 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -177,6 +177,7 @@ export interface SearchResult { episodes_titles: string[]; source: string; source_name: string; + weight?: number; // 播放源权重(来自后台配置,用于排序和优选评分) class?: string; year: string; desc?: string;