新增基于lxserver的音乐功能
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { db } from '@/lib/db';
|
||||
|
||||
export async function getMusicV2Username(request: NextRequest): Promise<string | null> {
|
||||
const authInfo = getAuthInfoFromCookie(request);
|
||||
if (!authInfo?.username) return null;
|
||||
|
||||
if (authInfo.username !== process.env.USERNAME) {
|
||||
const userInfo = await db.getUserInfoV2(authInfo.username);
|
||||
if (!userInfo || userInfo.banned) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return authInfo.username;
|
||||
}
|
||||
|
||||
export function unauthorized() {
|
||||
return NextResponse.json({ success: false, error: { code: 'UNAUTHORIZED', message: 'Unauthorized' } }, { status: 401 });
|
||||
}
|
||||
|
||||
export function badRequest(message: string, code = 'BAD_REQUEST') {
|
||||
return NextResponse.json({ success: false, error: { code, message } }, { status: 400 });
|
||||
}
|
||||
|
||||
export function internalError(message: string, details?: string) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: { code: 'INTERNAL_ERROR', message, details } },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user