openlist根路径主动移除bom
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -90,7 +90,7 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
if (listResponse.code !== 200) {
|
||||
return NextResponse.json(
|
||||
{ error: 'OpenList 列表获取失败' },
|
||||
{ error: 'OpenList 列表获取失败3' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user