feat: support editting live info

This commit is contained in:
shinya
2025-08-26 01:03:09 +08:00
parent ad3bf8f3bc
commit 5e93d608ee
4 changed files with 168 additions and 11 deletions

View File

@@ -102,6 +102,34 @@ export async function POST(request: NextRequest) {
disableSource.disabled = true;
break;
case 'edit':
// 编辑直播源
const editSource = config.LiveConfig.find((l) => l.key === key);
if (!editSource) {
return NextResponse.json({ error: '直播源不存在' }, { status: 404 });
}
// 配置文件中的直播源不允许编辑
if (editSource.from === 'config') {
return NextResponse.json({ error: '不能编辑配置文件中的直播源' }, { status: 400 });
}
// 更新字段(除了 key 和 from
editSource.name = name as string;
editSource.url = url as string;
editSource.ua = ua || '';
editSource.epg = epg || '';
// 刷新频道数
try {
const nums = await refreshLiveChannels(editSource);
editSource.channelNumber = nums;
} catch (error) {
console.error('刷新直播源失败:', error);
editSource.channelNumber = 0;
}
break;
case 'sort':
// 排序直播源
const { order } = body;

View File

@@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
});
if (!response.ok) {
return NextResponse.json({ error: 'Failed to fetch' }, { status: 500 });
return NextResponse.json({ error: 'Failed to fetch', message: response.statusText }, { status: 500 });
}
const contentType = response.headers.get('Content-Type');
@@ -43,6 +43,6 @@ export async function GET(request: NextRequest) {
}
return NextResponse.json({ success: true, type: 'm3u8' }, { status: 200 });
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch' }, { status: 500 });
return NextResponse.json({ error: 'Failed to fetch', message: error }, { status: 500 });
}
}

View File

@@ -39,8 +39,9 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Failed to fetch m3u8' }, { status: 500 });
}
const contentType = response.headers.get('Content-Type') || '';
// rewrite m3u8
if (response.headers.get('Content-Type')?.includes('application/vnd.apple.mpegurl')) {
if (contentType.toLowerCase().includes('mpegurl')) {
// 获取最终的响应URL处理重定向后的URL
const finalUrl = response.url;
const m3u8Content = await response.text();
@@ -52,7 +53,7 @@ export async function GET(request: Request) {
const modifiedContent = rewriteM3U8Content(m3u8Content, baseUrl, request, allowCORS);
const headers = new Headers();
headers.set('Content-Type', 'application/vnd.apple.mpegurl');
headers.set('Content-Type', contentType);
headers.set('Access-Control-Allow-Origin', '*');
headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
headers.set('Access-Control-Allow-Headers', 'Content-Type, Range, Origin, Accept');