存至私人影库增加下载方式

This commit is contained in:
mtvpls
2026-05-21 23:46:26 +08:00
parent e44f565112
commit a24de1346f
8 changed files with 159 additions and 16 deletions
+16 -2
View File
@@ -8,6 +8,13 @@ import { hasFeaturePermission } from '@/lib/permissions';
export const runtime = 'nodejs';
const downloadTools = ['aria2', 'Transmission', 'qBittorrent'] as const;
type DownloadTool = typeof downloadTools[number];
function isDownloadTool(tool: unknown): tool is DownloadTool {
return typeof tool === 'string' && downloadTools.includes(tool as DownloadTool);
}
/**
* POST /api/acg/download
* 添加 ACG 资源到 OpenList 离线下载(仅管理员和站长可用)
@@ -23,7 +30,7 @@ export async function POST(req: NextRequest) {
);
}
const { url, name } = await req.json();
const { url, name, tool = 'aria2' } = await req.json();
if (!url || typeof url !== 'string') {
return NextResponse.json(
@@ -39,6 +46,13 @@ export async function POST(req: NextRequest) {
);
}
if (!isDownloadTool(tool)) {
return NextResponse.json(
{ error: '下载方式不支持' },
{ status: 400 }
);
}
// 获取 OpenList 配置
const config = await getConfig();
const openlistConfig = config.OpenListConfig;
@@ -81,7 +95,7 @@ export async function POST(req: NextRequest) {
body: JSON.stringify({
path: downloadPath,
urls: [url],
tool: 'aria2',
tool,
}),
});