移除openlist token的输入

This commit is contained in:
mtvpls
2025-12-22 21:38:51 +08:00
parent 0450edf9bc
commit 84fa95fc57
14 changed files with 111 additions and 117 deletions

View File

@@ -26,7 +26,7 @@ export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { action, URL, Token, Username, Password, RootPath } = body;
const { action, URL, Username, Password, RootPath } = body;
const authInfo = getAuthInfoFromCookie(request);
if (!authInfo || !authInfo.username) {
@@ -49,40 +49,30 @@ export async function POST(request: NextRequest) {
if (action === 'save') {
// 保存配置
if (!URL) {
return NextResponse.json({ error: '缺少URL参数' }, { status: 400 });
}
let finalToken = Token;
// 如果没有Token但有账号密码尝试登录获取Token
if (!finalToken && Username && Password) {
try {
console.log('[OpenList Config] 使用账号密码登录获取Token');
finalToken = await OpenListClient.login(URL, Username, Password);
console.log('[OpenList Config] 登录成功获取到Token');
} catch (error) {
console.error('[OpenList Config] 登录失败:', error);
return NextResponse.json(
{ error: '使用账号密码登录失败: ' + (error as Error).message },
{ status: 400 }
);
}
}
// 检查是否有Token
if (!finalToken) {
if (!URL || !Username || !Password) {
return NextResponse.json(
{ error: '请提供Token或账号密码' },
{ error: '请提供 URL、账号密码' },
{ status: 400 }
);
}
// 验证账号密码是否正确
try {
console.log('[OpenList Config] 验证账号密码');
await OpenListClient.login(URL, Username, Password);
console.log('[OpenList Config] 账号密码验证成功');
} catch (error) {
console.error('[OpenList Config] 账号密码验证失败:', error);
return NextResponse.json(
{ error: '账号密码验证失败: ' + (error as Error).message },
{ status: 400 }
);
}
adminConfig.OpenListConfig = {
URL,
Token: finalToken,
Username: Username || undefined,
Password: Password || undefined,
Username,
Password,
RootPath: RootPath || '/',
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
ResourceCount: adminConfig.OpenListConfig?.ResourceCount,

View File

@@ -264,7 +264,7 @@ async function handleOpenListProxy(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json(
{ code: 0, msg: 'OpenList 未配置', list: [] },
{ status: 200 }
@@ -272,7 +272,11 @@ async function handleOpenListProxy(request: NextRequest) {
}
const rootPath = openListConfig.RootPath || '/';
const client = new OpenListClient(openListConfig.URL, openListConfig.Token);
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Username,
openListConfig.Password
);
// 读取 metainfo (从数据库或缓存)
let metaInfo: MetaInfo | null = getCachedMetaInfo(rootPath);

View File

@@ -26,7 +26,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
throw new Error('OpenList 未配置');
}

View File

@@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json(
{ error: 'OpenList 未配置' },
{ status: 400 }
@@ -49,7 +49,6 @@ export async function POST(request: NextRequest) {
const rootPath = openListConfig.RootPath || '/';
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Token,
openListConfig.Username,
openListConfig.Password
);

View File

@@ -35,7 +35,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json({ error: 'OpenList 未配置' }, { status: 400 });
}
@@ -43,7 +43,6 @@ export async function GET(request: NextRequest) {
const folderPath = `${rootPath}${rootPath.endsWith('/') ? '' : '/'}${folderName}`;
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Token,
openListConfig.Username,
openListConfig.Password
);

View File

@@ -34,7 +34,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json(
{ error: 'OpenList 未配置', list: [], total: 0 },
{ status: 200 }
@@ -44,7 +44,6 @@ export async function GET(request: NextRequest) {
const rootPath = openListConfig.RootPath || '/';
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Token,
openListConfig.Username,
openListConfig.Password
);

View File

@@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json({ error: 'OpenList 未配置' }, { status: 400 });
}
@@ -41,7 +41,6 @@ export async function GET(request: NextRequest) {
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Token,
openListConfig.Username,
openListConfig.Password
);

View File

@@ -30,7 +30,7 @@ export async function POST(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json({ error: 'OpenList 未配置' }, { status: 400 });
}
@@ -38,7 +38,6 @@ export async function POST(request: NextRequest) {
const folderPath = `${rootPath}${rootPath.endsWith('/') ? '' : '/'}${folder}`;
const client = new OpenListClient(
openListConfig.URL,
openListConfig.Token,
openListConfig.Username,
openListConfig.Password
);

View File

@@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
const config = await getConfig();
const openListConfig = config.OpenListConfig;
if (!openListConfig || !openListConfig.URL || !openListConfig.Token) {
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
return NextResponse.json(
{ error: 'OpenList 未配置' },
{ status: 400 }
@@ -66,7 +66,6 @@ export async function POST(request: NextRequest) {
performScan(
taskId,
openListConfig.URL,
openListConfig.Token,
openListConfig.RootPath || '/',
tmdbApiKey,
tmdbProxy,
@@ -97,20 +96,18 @@ export async function POST(request: NextRequest) {
async function performScan(
taskId: string,
url: string,
token: string,
rootPath: string,
tmdbApiKey: string,
tmdbProxy?: string,
username?: string,
password?: string
): Promise<void> {
const client = new OpenListClient(url, token, username, password);
const client = new OpenListClient(url, username!, password!);
console.log('[OpenList Refresh] 开始扫描:', {
taskId,
rootPath,
url,
hasToken: !!token,
});
// 立即更新进度,确保任务可被查询

View File

@@ -34,7 +34,7 @@ export async function GET(request: NextRequest) {
const apiSites = await getAvailableApiSites(authInfo.username);
// 检查是否配置了 OpenList
const hasOpenList = !!(config.OpenListConfig?.URL && config.OpenListConfig?.Token);
const hasOpenList = !!(config.OpenListConfig?.URL && config.OpenListConfig?.Username && config.OpenListConfig?.Password);
// 共享状态
let streamClosed = false;