openlist离线下载增加额外源选择

This commit is contained in:
mtvpls
2026-05-22 00:24:44 +08:00
parent a24de1346f
commit 7012a79210
7 changed files with 286 additions and 94 deletions
+9 -48
View File
@@ -3,7 +3,11 @@ import { NextRequest, NextResponse } from 'next/server';
import { getAuthInfoFromCookie } from '@/lib/auth';
import { getConfig } from '@/lib/config';
import { OpenListClient } from '@/lib/openlist.client';
import {
addOpenListOfflineDownload,
getOfflineDownloadBasePath,
joinOpenListPath,
} from '@/lib/openlist-offline-download';
import { hasFeaturePermission } from '@/lib/permissions';
export const runtime = 'nodejs';
@@ -55,56 +59,13 @@ export async function POST(req: NextRequest) {
// 获取 OpenList 配置
const config = await getConfig();
const openlistConfig = config.OpenListConfig;
if (!openlistConfig?.Enabled) {
return NextResponse.json(
{ error: '私人影库功能未启用' },
{ status: 400 }
);
}
if (!openlistConfig.URL || !openlistConfig.Username || !openlistConfig.Password) {
return NextResponse.json(
{ error: 'OpenList 配置不完整' },
{ status: 400 }
);
}
// 构建下载路径(使用离线下载目录)
const offlineDownloadPath = openlistConfig.OfflineDownloadPath || '/';
const downloadPath = `${offlineDownloadPath.replace(/\/$/, '')}/${name}`;
// 使用 OpenListClient 添加离线下载任务
const client = new OpenListClient(
openlistConfig.URL,
openlistConfig.Username,
openlistConfig.Password
const downloadPath = joinOpenListPath(
getOfflineDownloadBasePath(config),
name
);
// 获取 Token 并调用 API
const token = await (client as any).getToken();
const openlistUrl = `${openlistConfig.URL.replace(/\/$/, '')}/api/fs/add_offline_download`;
const response = await fetch(openlistUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': token,
},
body: JSON.stringify({
path: downloadPath,
urls: [url],
tool,
}),
});
const data = await response.json();
// 检查响应状态
if (!response.ok || data.code !== 200) {
throw new Error(data.message || '添加离线下载任务失败');
}
await addOpenListOfflineDownload(config, downloadPath, url, tool);
return NextResponse.json({
success: true,