feat: roughly admin info struct and interface

This commit is contained in:
shinya
2025-07-05 00:29:43 +08:00
parent 44ce8241c6
commit a4c56e2cdd
15 changed files with 1305 additions and 53 deletions

View File

@@ -0,0 +1,60 @@
/* eslint-disable no-console */
import { NextResponse } from 'next/server';
import { AdminConfigResult } from '@/lib/admin.types';
import { getConfig } from '@/lib/config';
export const runtime = 'edge';
export async function GET() {
try {
const config = getConfig();
const result: AdminConfigResult = {
Role: 'owner',
Config: config,
};
return NextResponse.json(result, {
headers: {
'Cache-Control': 'no-store', // 管理员配置不缓存
},
});
} catch (error) {
console.error('获取管理员配置失败:', error);
return NextResponse.json(
{
error: '获取管理员配置失败',
details: (error as Error).message,
},
{ status: 500 }
);
}
}
export async function POST(request: Request) {
try {
const updateData = await request.json();
// 在实际应用中,这里应该验证用户权限并更新配置
console.log('更新管理员配置:', updateData);
// 模拟配置更新
// 在实际应用中,这里应该将配置保存到数据库或配置文件
return NextResponse.json({
success: true,
message: '配置更新成功',
timestamp: new Date().toISOString(),
});
} catch (error) {
console.error('更新管理员配置失败:', error);
return NextResponse.json(
{
error: '更新管理员配置失败',
details: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { getApiSites, getCacheTime } from '@/lib/config';
import { getAvailableApiSites, getCacheTime } from '@/lib/config';
import { getDetailFromApi } from '@/lib/downstream';
export const runtime = 'edge';
@@ -19,7 +19,7 @@ export async function GET(request: Request) {
}
try {
const apiSites = getApiSites();
const apiSites = getAvailableApiSites();
const apiSite = apiSites.find((site) => site.key === sourceCode);
if (!apiSite) {

View File

@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import { NextRequest, NextResponse } from 'next/server';
import { getConfig } from '@/lib/config';
import { db } from '@/lib/db';
export const runtime = 'edge';
@@ -20,8 +21,9 @@ export async function POST(req: NextRequest) {
);
}
const config = getConfig();
// 校验是否开放注册
if (process.env.NEXT_PUBLIC_ENABLE_REGISTER !== 'true') {
if (!config.UserConfig.AllowRegister) {
return NextResponse.json({ error: '当前未开放注册' }, { status: 400 });
}

View File

@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { getApiSites, getCacheTime } from '@/lib/config';
import { getAvailableApiSites, getCacheTime } from '@/lib/config';
import { searchFromApi } from '@/lib/downstream';
export const runtime = 'edge';
@@ -21,7 +21,7 @@ export async function GET(request: Request) {
);
}
const apiSites = getApiSites();
const apiSites = getAvailableApiSites();
const searchPromises = apiSites.map((site) => searchFromApi(site, query));
try {