mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-06-11 11:33:10 +08:00
feat: make banned user logout
This commit is contained in:
@@ -1 +1 @@
|
|||||||
20250806184650
|
20250806191001
|
||||||
@@ -60,7 +60,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const userEntry = adminConfig.UserConfig.Users.find(
|
const userEntry = adminConfig.UserConfig.Users.find(
|
||||||
(u) => u.username === username
|
(u) => u.username === username
|
||||||
);
|
);
|
||||||
if (!userEntry || userEntry.role !== 'admin') {
|
if (!userEntry || userEntry.role !== 'admin' || userEntry.banned) {
|
||||||
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export async function GET(request: NextRequest) {
|
|||||||
result.Role = 'owner';
|
result.Role = 'owner';
|
||||||
} else {
|
} else {
|
||||||
const user = config.UserConfig.Users.find((u) => u.username === username);
|
const user = config.UserConfig.Users.find((u) => u.username === username);
|
||||||
if (user && user.role === 'admin') {
|
if (user && user.role === 'admin' && !user.banned) {
|
||||||
result.Role = 'admin';
|
result.Role = 'admin';
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const user = adminConfig.UserConfig.Users.find(
|
const user = adminConfig.UserConfig.Users.find(
|
||||||
(u) => u.username === username
|
(u) => u.username === username
|
||||||
);
|
);
|
||||||
if (!user || user.role !== 'admin') {
|
if (!user || user.role !== 'admin' || user.banned) {
|
||||||
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const userEntry = adminConfig.UserConfig.Users.find(
|
const userEntry = adminConfig.UserConfig.Users.find(
|
||||||
(u) => u.username === username
|
(u) => u.username === username
|
||||||
);
|
);
|
||||||
if (!userEntry || userEntry.role !== 'admin') {
|
if (!userEntry || userEntry.role !== 'admin' || userEntry.banned) {
|
||||||
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const userEntry = adminConfig.UserConfig.Users.find(
|
const userEntry = adminConfig.UserConfig.Users.find(
|
||||||
(u) => u.username === username
|
(u) => u.username === username
|
||||||
);
|
);
|
||||||
if (!userEntry || userEntry.role !== 'admin') {
|
if (!userEntry || userEntry.role !== 'admin' || userEntry.banned) {
|
||||||
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
return NextResponse.json({ error: '权限不足' }, { status: 401 });
|
||||||
}
|
}
|
||||||
operatorRole = 'admin';
|
operatorRole = 'admin';
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||||
|
import { getConfig } from '@/lib/config';
|
||||||
import { db } from '@/lib/db';
|
import { db } from '@/lib/db';
|
||||||
import { Favorite } from '@/lib/types';
|
import { Favorite } from '@/lib/types';
|
||||||
|
|
||||||
@@ -23,6 +24,17 @@ export async function GET(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const key = searchParams.get('key');
|
const key = searchParams.get('key');
|
||||||
|
|
||||||
@@ -63,6 +75,17 @@ export async function POST(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { key, favorite }: { key: string; favorite: Favorite } = body;
|
const { key, favorite }: { key: string; favorite: Favorite } = body;
|
||||||
|
|
||||||
@@ -120,6 +143,17 @@ export async function DELETE(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const username = authInfo.username;
|
const username = authInfo.username;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const key = searchParams.get('key');
|
const key = searchParams.get('key');
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||||
|
import { getConfig } from '@/lib/config';
|
||||||
import { db } from '@/lib/db';
|
import { db } from '@/lib/db';
|
||||||
import { PlayRecord } from '@/lib/types';
|
import { PlayRecord } from '@/lib/types';
|
||||||
|
|
||||||
@@ -16,6 +17,17 @@ export async function GET(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const records = await db.getAllPlayRecords(authInfo.username);
|
const records = await db.getAllPlayRecords(authInfo.username);
|
||||||
return NextResponse.json(records, { status: 200 });
|
return NextResponse.json(records, { status: 200 });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -35,6 +47,17 @@ export async function POST(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { key, record }: { key: string; record: PlayRecord } = body;
|
const { key, record }: { key: string; record: PlayRecord } = body;
|
||||||
|
|
||||||
@@ -87,6 +110,17 @@ export async function DELETE(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const username = authInfo.username;
|
const username = authInfo.username;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const key = searchParams.get('key');
|
const key = searchParams.get('key');
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||||
|
import { getConfig } from '@/lib/config';
|
||||||
import { db } from '@/lib/db';
|
import { db } from '@/lib/db';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
@@ -22,6 +23,17 @@ export async function GET(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const history = await db.getSearchHistory(authInfo.username);
|
const history = await db.getSearchHistory(authInfo.username);
|
||||||
return NextResponse.json(history, { status: 200 });
|
return NextResponse.json(history, { status: 200 });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -45,6 +57,17 @@ export async function POST(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const keyword: string = body.keyword?.trim();
|
const keyword: string = body.keyword?.trim();
|
||||||
|
|
||||||
@@ -83,6 +106,17 @@ export async function DELETE(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const kw = searchParams.get('keyword')?.trim();
|
const kw = searchParams.get('keyword')?.trim();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||||
|
import { getConfig } from '@/lib/config';
|
||||||
import { db } from '@/lib/db';
|
import { db } from '@/lib/db';
|
||||||
import { SkipConfig } from '@/lib/types';
|
import { SkipConfig } from '@/lib/types';
|
||||||
|
|
||||||
@@ -15,6 +16,17 @@ export async function GET(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = await getConfig();
|
||||||
|
if (config.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = config.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const source = searchParams.get('source');
|
const source = searchParams.get('source');
|
||||||
const id = searchParams.get('id');
|
const id = searchParams.get('id');
|
||||||
@@ -44,6 +56,17 @@ export async function POST(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adminConfig = await getConfig();
|
||||||
|
if (adminConfig.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = adminConfig.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { key, config } = body;
|
const { key, config } = body;
|
||||||
|
|
||||||
@@ -83,6 +106,17 @@ export async function DELETE(request: NextRequest) {
|
|||||||
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adminConfig = await getConfig();
|
||||||
|
if (adminConfig.UserConfig.Users) {
|
||||||
|
// 检查用户是否被封禁
|
||||||
|
const user = adminConfig.UserConfig.Users.find(
|
||||||
|
(u) => u.username === authInfo.username
|
||||||
|
);
|
||||||
|
if (user && user.banned) {
|
||||||
|
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const key = searchParams.get('key');
|
const key = searchParams.get('key');
|
||||||
|
|
||||||
|
|||||||
@@ -414,6 +414,15 @@ async function fetchWithAuth(
|
|||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// 如果是 401 未授权,跳转到登录页面
|
// 如果是 401 未授权,跳转到登录页面
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
|
// 调用 logout 接口
|
||||||
|
try {
|
||||||
|
await fetch('/api/logout', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('注销请求失败:', error);
|
||||||
|
}
|
||||||
const currentUrl = window.location.pathname + window.location.search;
|
const currentUrl = window.location.pathname + window.location.search;
|
||||||
const loginUrl = new URL('/login', window.location.origin);
|
const loginUrl = new URL('/login', window.location.origin);
|
||||||
loginUrl.searchParams.set('redirect', currentUrl);
|
loginUrl.searchParams.set('redirect', currentUrl);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
const CURRENT_VERSION = '20250806184650';
|
const CURRENT_VERSION = '20250806191001';
|
||||||
|
|
||||||
// 版本检查结果枚举
|
// 版本检查结果枚举
|
||||||
export enum UpdateStatus {
|
export enum UpdateStatus {
|
||||||
|
|||||||
Reference in New Issue
Block a user