emby支持多源

This commit is contained in:
mtvpls
2026-01-08 00:14:07 +08:00
parent b61db02478
commit 2736c9e845
22 changed files with 1316 additions and 572 deletions

View File

@@ -78,3 +78,54 @@ export async function GET(request: NextRequest) {
);
}
}
export async function POST(request: NextRequest) {
const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage';
if (storageType === 'localstorage') {
return NextResponse.json(
{ error: '不支持本地存储进行管理员配置' },
{ status: 400 }
);
}
const authInfo = getAuthInfoFromCookie(request);
if (!authInfo || !authInfo.username) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const username = authInfo.username;
try {
const newConfig = await request.json();
// 权限检查
if (username !== process.env.USERNAME) {
const { db } = await import('@/lib/db');
const userInfoV2 = await db.getUserInfoV2(username);
if (!userInfoV2 || (userInfoV2.role !== 'admin' && userInfoV2.role !== 'owner') || userInfoV2.banned) {
return NextResponse.json({ error: '权限不足' }, { status: 401 });
}
}
// 保存配置
const { db } = await import('@/lib/db');
const { configSelfCheck, setCachedConfig } = await import('@/lib/config');
// 自检配置
const checkedConfig = configSelfCheck(newConfig);
// 保存到数据库
await db.saveAdminConfig(checkedConfig);
// 更新缓存
await setCachedConfig(checkedConfig);
return NextResponse.json({ success: true, message: '配置已保存' });
} catch (error) {
console.error('保存配置失败:', error);
return NextResponse.json(
{ error: '保存配置失败: ' + (error as Error).message },
{ status: 500 }
);
}
}