openlist根路径主动移除bom
This commit is contained in:
@@ -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<void> {
|
||||
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;
|
||||
|
||||
@@ -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'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user