mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-01 00:16:52 +08:00
feat: config subscription
This commit is contained in:
@@ -40,7 +40,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
// 获取请求体
|
||||
const body = await request.json();
|
||||
const { configFile } = body;
|
||||
const { configFile, subscriptionUrl, autoUpdate, lastCheckTime } = body;
|
||||
|
||||
if (!configFile || typeof configFile !== 'string') {
|
||||
return NextResponse.json(
|
||||
@@ -60,6 +60,17 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
adminConfig.ConfigFile = configFile;
|
||||
|
||||
// 更新订阅配置
|
||||
if (subscriptionUrl !== undefined) {
|
||||
adminConfig.ConfigSubscribtion.URL = subscriptionUrl;
|
||||
}
|
||||
if (autoUpdate !== undefined) {
|
||||
adminConfig.ConfigSubscribtion.AutoUpdate = autoUpdate;
|
||||
}
|
||||
// 更新最后检查时间 - 使用前端传递的时间或当前时间
|
||||
adminConfig.ConfigSubscribtion.LastCheck = lastCheckTime || '';
|
||||
|
||||
adminConfig = refineConfig(adminConfig);
|
||||
// 更新配置文件
|
||||
if (storage && typeof (storage as any).setAdminConfig === 'function') {
|
||||
|
||||
36
src/app/api/admin/config_subscription/fetch/route.ts
Normal file
36
src/app/api/admin/config_subscription/fetch/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { url } = await request.json();
|
||||
|
||||
if (!url) {
|
||||
return NextResponse.json({ error: '缺少URL参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 直接 fetch URL 获取配置内容
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: `请求失败: ${response.status} ${response.statusText}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
const configContent = await response.text();
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
configContent,
|
||||
message: '配置拉取成功'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('拉取配置失败:', error);
|
||||
return NextResponse.json(
|
||||
{ error: '拉取配置失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user