test prod emby

This commit is contained in:
mtvpls
2026-01-12 23:54:22 +08:00
parent 3f610124e7
commit 033eae152b
6 changed files with 82 additions and 25 deletions

View File

@@ -9,7 +9,10 @@ export const runtime = 'nodejs';
*/
export async function GET() {
try {
console.log('[Emby Sources API] 开始获取Emby源列表');
const sources = await embyManager.getEnabledSources();
console.log('[Emby Sources API] 获取到的源数量:', sources.length);
console.log('[Emby Sources API] 源详情:', JSON.stringify(sources, null, 2));
return NextResponse.json({
sources: sources.map(s => ({

View File

@@ -45,11 +45,18 @@ export async function PATCH(
try {
const storage = getStorage();
const userInfo = await storage.getUserInfoV2(authInfo.username);
// 检查权限:只有管理员和站长可以操作
if (userInfo?.role !== 'admin' && userInfo?.role !== 'owner') {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
if (storage.getUserInfoV2) {
const userInfo = await storage.getUserInfoV2(authInfo.username);
if (userInfo?.role !== 'admin' && userInfo?.role !== 'owner') {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
}
} else {
// 如果不支持 getUserInfoV2只允许站长操作
if (authInfo.username !== process.env.USERNAME) {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
}
}
const body = await request.json();
@@ -116,11 +123,18 @@ export async function DELETE(
try {
const storage = getStorage();
const userInfo = await storage.getUserInfoV2(authInfo.username);
// 检查权限:只有管理员和站长可以删除
if (userInfo?.role !== 'admin' && userInfo?.role !== 'owner') {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
if (storage.getUserInfoV2) {
const userInfo = await storage.getUserInfoV2(authInfo.username);
if (userInfo?.role !== 'admin' && userInfo?.role !== 'owner') {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
}
} else {
// 如果不支持 getUserInfoV2只允许站长操作
if (authInfo.username !== process.env.USERNAME) {
return NextResponse.json({ error: '无权限操作' }, { status: 403 });
}
}
const movieRequest = await storage.getMovieRequest(params.id);

View File

@@ -42,7 +42,7 @@ export async function GET(request: NextRequest) {
// 列表页不返回 requestedBy
if (!detail) {
requests = requests.map(r => ({ ...r, requestedBy: undefined }));
requests = requests.map(r => ({ ...r, requestedBy: [] }));
}
// 按求片人数和时间排序
@@ -92,15 +92,17 @@ export async function POST(request: NextRequest) {
const cooldownSeconds = config.SiteConfig.MovieRequestCooldown ?? 3600;
const rateLimit = cooldownSeconds * 1000;
const userInfo = await storage.getUserInfoV2(authInfo.username);
if (userInfo?.last_movie_request_time) {
const elapsed = Date.now() - userInfo.last_movie_request_time;
if (elapsed < rateLimit) {
const remaining = Math.ceil((rateLimit - elapsed) / 60000);
return NextResponse.json(
{ error: `操作太频繁,请${remaining}分钟后再试` },
{ status: 429 }
);
if (storage.getUserInfoV2) {
const userInfo = await storage.getUserInfoV2(authInfo.username);
if (userInfo?.last_movie_request_time) {
const elapsed = Date.now() - userInfo.last_movie_request_time;
if (elapsed < rateLimit) {
const remaining = Math.ceil((rateLimit - elapsed) / 60000);
return NextResponse.json(
{ error: `操作太频繁,请${remaining}分钟后再试` },
{ status: 429 }
);
}
}
}
@@ -173,15 +175,17 @@ export async function POST(request: NextRequest) {
await storage.addUserMovieRequest(authInfo.username, newRequest.id);
// 更新频率限制 - 保存到用户信息的 hash 中
await storage.client.hSet(
`user:${authInfo.username}:info`,
'last_movie_request_time',
Date.now().toString()
);
if ('client' in storage && storage.client && typeof (storage.client as any).hSet === 'function') {
await (storage.client as any).hSet(
`user:${authInfo.username}:info`,
'last_movie_request_time',
Date.now().toString()
);
// 清除用户信息缓存,确保下次读取到最新数据
const { userInfoCache } = await import('@/lib/user-cache');
userInfoCache?.delete(authInfo.username);
// 清除用户信息缓存,确保下次读取到最新数据
const { userInfoCache } = await import('@/lib/user-cache');
userInfoCache?.delete(authInfo.username);
}
// 给站长发送通知
const ownerUsername = process.env.USERNAME;