- 创建统一的下载错误处理模块 (lib/download-errors.ts) - 实现13种错误类型分类和中文错误消息 - 后端统一使用 createDownloadError 创建标准化错误响应 - 前端统一使用 parseDownloadError 解析错误并显示 - 修复正式系统数据库Schema,添加产品全案相关字段和表 - 执行数据库迁移:添加 task_no, task_status, task_fetched_at 字段 - 创建 material_assets, api_keys, api_call_logs 表
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
/**
|
|
* API 调用日志接口
|
|
* GET - 获取调用日志列表
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/lib/auth';
|
|
import { isSuperAdmin, hasSystemAdminPermission } from '@/lib/department-permission';
|
|
import { getApiCallLogs } from '@/lib/external-api';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json(
|
|
{ success: false, error: '未登录' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
// 检查权限
|
|
const isSuperAdminUser = await isSuperAdmin(session.user.id);
|
|
const hasPermission = hasSystemAdminPermission(session.user.role, isSuperAdminUser);
|
|
|
|
if (!hasPermission) {
|
|
return NextResponse.json(
|
|
{ success: false, error: '无权限访问' },
|
|
{ status: 403 }
|
|
);
|
|
}
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const apiKeyId = searchParams.get('apiKeyId') || undefined;
|
|
const taskNo = searchParams.get('taskNo') || undefined;
|
|
const startDate = searchParams.get('startDate');
|
|
const endDate = searchParams.get('endDate');
|
|
const limit = parseInt(searchParams.get('limit') || '50');
|
|
const offset = parseInt(searchParams.get('offset') || '0');
|
|
|
|
const options: any = {
|
|
apiKeyId,
|
|
taskNo,
|
|
limit,
|
|
offset,
|
|
};
|
|
|
|
if (startDate) {
|
|
options.startDate = new Date(startDate);
|
|
}
|
|
if (endDate) {
|
|
options.endDate = new Date(endDate);
|
|
}
|
|
|
|
const result = await getApiCallLogs(options);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: {
|
|
logs: result.logs,
|
|
total: result.total,
|
|
limit,
|
|
offset,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('[admin/api-logs] GET error:', error);
|
|
return NextResponse.json(
|
|
{ success: false, error: '服务器错误' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|