增加网络直播
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getConfig } from '@/lib/config';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
if (!config?.WebLiveConfig) {
|
||||
return NextResponse.json([]);
|
||||
}
|
||||
|
||||
const sources = config.WebLiveConfig.filter(s => !s.disabled);
|
||||
return NextResponse.json(sources);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '获取失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const platform = searchParams.get('platform');
|
||||
const roomId = searchParams.get('roomId');
|
||||
|
||||
if (!platform || !roomId) {
|
||||
return NextResponse.json({ error: '缺少参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (platform === 'huya') {
|
||||
const res = await fetch(`https://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=${roomId}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.status === 200 && data.data?.liveStatus === 'ON') {
|
||||
const stream = data.data.stream;
|
||||
const url = `${stream.flv.multiLine[0].url}/${stream.flv.streamName}.${stream.flv.sFlvUrlSuffix}?${stream.flv.sFlvAntiCode}`;
|
||||
return NextResponse.json({ url });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: '直播未开启' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: '不支持的平台' }, { status: 400 });
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '获取失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user