From f43bdaa9e31699891e2a854f61e8f09b2f5808ec Mon Sep 17 00:00:00 2001 From: mtvpls Date: Fri, 6 Feb 2026 21:28:57 +0800 Subject: [PATCH] =?UTF-8?q?openlist=E6=A0=B9=E8=B7=AF=E5=BE=84=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E7=A7=BB=E9=99=A4bom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/admin/openlist/route.ts | 17 +++++++++++- src/app/api/detail/route.ts | 2 +- .../api/openlist/cms-proxy/[token]/route.ts | 2 +- src/app/api/openlist/detail/route.ts | 2 +- src/app/api/source-detail/route.ts | 2 +- src/app/play/page.tsx | 20 +++++--------- src/lib/openlist-refresh.ts | 26 ++++++++++++++----- src/lib/openlist.client.ts | 3 +-- src/lib/special-sources-detail.ts | 2 +- 9 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/app/api/admin/openlist/route.ts b/src/app/api/admin/openlist/route.ts index 5914b4e..0728b23 100644 --- a/src/app/api/admin/openlist/route.ts +++ b/src/app/api/admin/openlist/route.ts @@ -9,6 +9,18 @@ import { OpenListClient } from '@/lib/openlist.client'; export const runtime = 'nodejs'; +/** + * 清理字符串中的 BOM 和其他不可见字符 + */ +function cleanPath(path: string): string { + // 移除 UTF-8 BOM (U+FEFF) 和其他零宽度字符 + return path + .replace(/^\uFEFF/, '') // 移除开头的 BOM + .replace(/\uFEFF/g, '') // 移除所有 BOM + .replace(/[\u200B-\u200D\uFEFF]/g, '') // 移除零宽度字符 + .trim(); // 移除首尾空白 +} + /** * POST /api/admin/openlist * 保存 OpenList 配置 @@ -86,6 +98,9 @@ export async function POST(request: NextRequest) { ); } + // 清理 RootPaths 中的 BOM 和不可见字符 + const cleanedRootPaths = RootPaths.map(cleanPath); + // 验证扫描间隔 const scanInterval = parseInt(ScanInterval) || 0; if (scanInterval > 0 && scanInterval < 60) { @@ -113,7 +128,7 @@ export async function POST(request: NextRequest) { URL, Username, Password, - RootPaths, + RootPaths: cleanedRootPaths, OfflineDownloadPath: OfflineDownloadPath || '/', LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime, ResourceCount: adminConfig.OpenListConfig?.ResourceCount, diff --git a/src/app/api/detail/route.ts b/src/app/api/detail/route.ts index cb6901c..ae3a696 100644 --- a/src/app/api/detail/route.ts +++ b/src/app/api/detail/route.ts @@ -91,7 +91,7 @@ export async function GET(request: NextRequest) { const listResponse = await client.listDirectory(folderPath, currentPage, pageSize); if (listResponse.code !== 200) { - throw new Error('OpenList 列表获取失败'); + throw new Error('OpenList 列表获取失败1'); } total = listResponse.data.total; diff --git a/src/app/api/openlist/cms-proxy/[token]/route.ts b/src/app/api/openlist/cms-proxy/[token]/route.ts index 489673f..97d2834 100644 --- a/src/app/api/openlist/cms-proxy/[token]/route.ts +++ b/src/app/api/openlist/cms-proxy/[token]/route.ts @@ -279,7 +279,7 @@ async function handleDetail( if (listResponse.code !== 200) { return NextResponse.json({ code: 0, - msg: 'OpenList 列表获取失败', + msg: 'OpenList 列表获取失败2', page: 1, pagecount: 0, limit: 0, diff --git a/src/app/api/openlist/detail/route.ts b/src/app/api/openlist/detail/route.ts index fc69fbe..54fdec8 100644 --- a/src/app/api/openlist/detail/route.ts +++ b/src/app/api/openlist/detail/route.ts @@ -90,7 +90,7 @@ export async function GET(request: NextRequest) { if (listResponse.code !== 200) { return NextResponse.json( - { error: 'OpenList 列表获取失败' }, + { error: 'OpenList 列表获取失败3' }, { status: 500 } ); } diff --git a/src/app/api/source-detail/route.ts b/src/app/api/source-detail/route.ts index 5dc2f8e..00be402 100644 --- a/src/app/api/source-detail/route.ts +++ b/src/app/api/source-detail/route.ts @@ -293,7 +293,7 @@ export async function GET(request: NextRequest) { const listResponse = await client.listDirectory(folderPath, currentPage, pageSize); if (listResponse.code !== 200) { - throw new Error('OpenList 列表获取失败'); + throw new Error('OpenList 列表获取失败4'); } total = listResponse.data.total; diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index b860ee2..3e035d5 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -1805,19 +1805,13 @@ function PlayPageClient() { clearRefreshTimer(); // 清除旧的定时器 isInitialLoadRef.current = true; // 重置为首次加载 - // 动态设置 referrer policy:只在小雅源时不发送 Referer + // 动态设置 referrer policy:不发送 Referer const existingMeta = document.querySelector('meta[name="referrer"]'); - if (detailData?.source === 'xiaoya') { - if (!existingMeta) { - const meta = document.createElement('meta'); - meta.name = 'referrer'; - meta.content = 'no-referrer'; - document.head.appendChild(meta); - } - } else { - if (existingMeta) { - existingMeta.remove(); - } + if (!existingMeta) { + const meta = document.createElement('meta'); + meta.name = 'referrer'; + meta.content = 'no-referrer'; + document.head.appendChild(meta); } if ( @@ -4847,7 +4841,7 @@ function PlayPageClient() { moreVideoAttr: { playsInline: true, 'webkit-playsinline': 'true', - ...(detail?.source === 'xiaoya' ? { referrerpolicy: 'no-referrer' } : {}), + referrerpolicy: 'no-referrer', } as any, // HLS 支持配置 customType: { diff --git a/src/lib/openlist-refresh.ts b/src/lib/openlist-refresh.ts index 9409b39..48b3f14 100644 --- a/src/lib/openlist-refresh.ts +++ b/src/lib/openlist-refresh.ts @@ -25,19 +25,31 @@ import { getTVSeasonDetails,searchTMDB } from '@/lib/tmdb.search'; /** * 获取根目录列表(兼容新旧配置) */ +/** + * 清理字符串中的 BOM 和其他不可见字符 + */ +function cleanPath(path: string): string { + // 移除 UTF-8 BOM (U+FEFF) 和其他零宽度字符 + return path + .replace(/^\uFEFF/, '') // 移除开头的 BOM + .replace(/\uFEFF/g, '') // 移除所有 BOM + .replace(/[\u200B-\u200D\uFEFF]/g, '') // 移除零宽度字符 + .trim(); // 移除首尾空白 +} + function getRootPaths(openListConfig: AdminConfig['OpenListConfig']): string[] { if (!openListConfig) { return ['/']; } - // 如果有新字段 RootPaths,直接使用 + // 如果有新字段 RootPaths,直接使用并清理 if (openListConfig.RootPaths && openListConfig.RootPaths.length > 0) { - return openListConfig.RootPaths; + return openListConfig.RootPaths.map(cleanPath); } - // 如果只tPath,返回单元素数组 + // 如果只有 RootPath,返回单元素数组并清理 if (openListConfig.RootPath) { - return [openListConfig.RootPath]; + return [cleanPath(openListConfig.RootPath)]; } // 默认值 @@ -155,8 +167,8 @@ async function performMultiRootScan( ): Promise { for (let i = 0; i < rootPaths.length; i++) { const rootPath = rootPaths[i]; - console.log(`[OpenList Refresh] 扫描根目录 (${i + 1}/${rootPaths.length}): ${rootPath}`); + console.log(`[OpenList Refresh] 扫描根目录 (${i + 1}/${rootPaths.length}): ${rootPath}`); try { await performScan( taskId, @@ -233,9 +245,9 @@ async function performScan( while (true) { const listResponse = await client.listDirectory(rootPath, currentPage, pageSize, true); - + console.log(listResponse); if (listResponse.code !== 200) { - throw new Error('OpenList 列表获取失败'); + throw new Error('OpenList 列表获取失败5'); } total = listResponse.data.total; diff --git a/src/lib/openlist.client.ts b/src/lib/openlist.client.ts index 1b0f448..ee14daf 100644 --- a/src/lib/openlist.client.ts +++ b/src/lib/openlist.client.ts @@ -158,7 +158,6 @@ export class OpenListClient { console.warn('[OpenListClient] 解析响应 JSON 失败:', error); } } - return response; } @@ -166,7 +165,7 @@ export class OpenListClient { const token = await this.getToken(); return { Authorization: token, // 不带 bearer - 'Content-Type': 'application/json', + 'Content-Type': 'application/json' }; } diff --git a/src/lib/special-sources-detail.ts b/src/lib/special-sources-detail.ts index 1cc4cfb..138cda0 100644 --- a/src/lib/special-sources-detail.ts +++ b/src/lib/special-sources-detail.ts @@ -178,7 +178,7 @@ export async function getOpenListDetail( ); if (listResponse.code !== 200) { - throw new Error('OpenList 列表获取失败'); + throw new Error('OpenList 列表获取失败6'); } total = listResponse.data.total;