增加自定义去广告功能
This commit is contained in:
28
src/app/api/ad-filter/route.ts
Normal file
28
src/app/api/ad-filter/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { getConfig } from '@/lib/config';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
/**
|
||||
* GET /api/ad-filter
|
||||
* 获取自定义去广告代码配置(公开接口,无需认证)
|
||||
* 返回代码内容和版本号,客户端通过版本号判断是否需要更新缓存
|
||||
*/
|
||||
export async function GET() {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
|
||||
// 返回自定义去广告代码和版本号
|
||||
return NextResponse.json({
|
||||
code: config.SiteConfig?.CustomAdFilterCode || '',
|
||||
version: config.SiteConfig?.CustomAdFilterVersion || 0,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('获取去广告代码配置失败:', error);
|
||||
return NextResponse.json(
|
||||
{ error: '获取配置失败', details: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,8 @@ export async function POST(request: NextRequest) {
|
||||
DanmakuApiBase,
|
||||
DanmakuApiToken,
|
||||
EnableComments,
|
||||
CustomAdFilterCode,
|
||||
CustomAdFilterVersion,
|
||||
} = body as {
|
||||
SiteName: string;
|
||||
Announcement: string;
|
||||
@@ -56,6 +58,8 @@ export async function POST(request: NextRequest) {
|
||||
DanmakuApiBase: string;
|
||||
DanmakuApiToken: string;
|
||||
EnableComments: boolean;
|
||||
CustomAdFilterCode?: string;
|
||||
CustomAdFilterVersion?: number;
|
||||
};
|
||||
|
||||
// 参数校验
|
||||
@@ -72,7 +76,9 @@ export async function POST(request: NextRequest) {
|
||||
typeof FluidSearch !== 'boolean' ||
|
||||
typeof DanmakuApiBase !== 'string' ||
|
||||
typeof DanmakuApiToken !== 'string' ||
|
||||
typeof EnableComments !== 'boolean'
|
||||
typeof EnableComments !== 'boolean' ||
|
||||
(CustomAdFilterCode !== undefined && typeof CustomAdFilterCode !== 'string') ||
|
||||
(CustomAdFilterVersion !== undefined && typeof CustomAdFilterVersion !== 'number')
|
||||
) {
|
||||
return NextResponse.json({ error: '参数格式错误' }, { status: 400 });
|
||||
}
|
||||
@@ -105,6 +111,8 @@ export async function POST(request: NextRequest) {
|
||||
DanmakuApiBase,
|
||||
DanmakuApiToken,
|
||||
EnableComments,
|
||||
CustomAdFilterCode,
|
||||
CustomAdFilterVersion,
|
||||
};
|
||||
|
||||
// 写入数据库
|
||||
|
||||
Reference in New Issue
Block a user