存至私人影库增加下载方式
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,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -23,10 +23,14 @@ export async function GET(req: NextRequest) {
|
||||
const config = await getConfig();
|
||||
const animeConfig = config.AnimeSubscriptionConfig || {
|
||||
Enabled: false,
|
||||
DownloadTool: 'aria2',
|
||||
Subscriptions: [],
|
||||
};
|
||||
|
||||
return NextResponse.json(animeConfig);
|
||||
return NextResponse.json({
|
||||
...animeConfig,
|
||||
DownloadTool: animeConfig.DownloadTool || 'aria2',
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('获取追番订阅配置失败:', error);
|
||||
return NextResponse.json(
|
||||
@@ -63,7 +67,13 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
const config = await getConfig();
|
||||
if (!config.AnimeSubscriptionConfig) {
|
||||
config.AnimeSubscriptionConfig = { Enabled: false, Subscriptions: [] };
|
||||
config.AnimeSubscriptionConfig = {
|
||||
Enabled: false,
|
||||
DownloadTool: 'aria2',
|
||||
Subscriptions: [],
|
||||
};
|
||||
} else if (!config.AnimeSubscriptionConfig.DownloadTool) {
|
||||
config.AnimeSubscriptionConfig.DownloadTool = 'aria2';
|
||||
}
|
||||
|
||||
// 验证集数
|
||||
|
||||
@@ -7,6 +7,13 @@ import { db } from '@/lib/db';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
const downloadTools = ['aria2', 'qBittorrent', 'Transmission'] as const;
|
||||
type DownloadTool = typeof downloadTools[number];
|
||||
|
||||
function isDownloadTool(tool: unknown): tool is DownloadTool {
|
||||
return typeof tool === 'string' && downloadTools.includes(tool as DownloadTool);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/admin/anime-subscription/toggle
|
||||
* 切换追番功能启用状态
|
||||
@@ -19,7 +26,7 @@ export async function PUT(req: NextRequest) {
|
||||
return NextResponse.json({ error: '无权限访问' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { enabled } = await req.json();
|
||||
const { enabled, downloadTool } = await req.json();
|
||||
|
||||
if (typeof enabled !== 'boolean') {
|
||||
return NextResponse.json(
|
||||
@@ -28,15 +35,31 @@ export async function PUT(req: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
if (downloadTool !== undefined && !isDownloadTool(downloadTool)) {
|
||||
return NextResponse.json(
|
||||
{ error: '下载方式不支持' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const config = await getConfig();
|
||||
if (!config.AnimeSubscriptionConfig) {
|
||||
config.AnimeSubscriptionConfig = { Enabled: false, Subscriptions: [] };
|
||||
}
|
||||
|
||||
config.AnimeSubscriptionConfig.Enabled = enabled;
|
||||
if (downloadTool !== undefined) {
|
||||
config.AnimeSubscriptionConfig.DownloadTool = downloadTool;
|
||||
} else if (!config.AnimeSubscriptionConfig.DownloadTool) {
|
||||
config.AnimeSubscriptionConfig.DownloadTool = 'aria2';
|
||||
}
|
||||
await db.saveAdminConfig(config);
|
||||
|
||||
return NextResponse.json({ success: true, enabled });
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
enabled,
|
||||
downloadTool: config.AnimeSubscriptionConfig.DownloadTool,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('切换追番功能状态失败:', error);
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user