视频源权重

This commit is contained in:
mtvpls
2026-01-28 18:21:08 +08:00
parent 7c62e1612c
commit ada7d12fa3
6 changed files with 151 additions and 9 deletions

View File

@@ -9,7 +9,7 @@ import { db } from '@/lib/db';
export const runtime = 'nodejs';
// 支持的操作类型
type Action = 'add' | 'disable' | 'enable' | 'delete' | 'sort' | 'batch_disable' | 'batch_enable' | 'batch_delete' | 'toggle_proxy_mode';
type Action = 'add' | 'disable' | 'enable' | 'delete' | 'sort' | 'batch_disable' | 'batch_enable' | 'batch_delete' | 'toggle_proxy_mode' | 'update_weight';
interface BaseBody {
action?: Action;
@@ -37,7 +37,7 @@ export async function POST(request: NextRequest) {
const username = authInfo.username;
// 基础校验
const ACTIONS: Action[] = ['add', 'disable', 'enable', 'delete', 'sort', 'batch_disable', 'batch_enable', 'batch_delete', 'toggle_proxy_mode'];
const ACTIONS: Action[] = ['add', 'disable', 'enable', 'delete', 'sort', 'batch_disable', 'batch_enable', 'batch_delete', 'toggle_proxy_mode', 'update_weight'];
if (!username || !action || !ACTIONS.includes(action)) {
return NextResponse.json({ error: '参数格式错误' }, { status: 400 });
}
@@ -254,6 +254,20 @@ export async function POST(request: NextRequest) {
entry.proxyMode = !entry.proxyMode;
break;
}
case 'update_weight': {
const { key, weight } = body as { key?: string; weight?: number };
if (!key)
return NextResponse.json({ error: '缺少 key 参数' }, { status: 400 });
if (weight === undefined || weight === null)
return NextResponse.json({ error: '缺少 weight 参数' }, { status: 400 });
if (typeof weight !== 'number' || weight < 0 || weight > 100)
return NextResponse.json({ error: '权重必须是 0-100 之间的数字' }, { status: 400 });
const entry = adminConfig.SourceConfig.find((s) => s.key === key);
if (!entry)
return NextResponse.json({ error: '源不存在' }, { status: 404 });
entry.weight = weight;
break;
}
default:
return NextResponse.json({ error: '未知操作' }, { status: 400 });
}