存至私人影库增加下载方式
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user