24 lines
807 B
TypeScript
24 lines
807 B
TypeScript
// server/api/stats.get.ts - 服务运行统计接口
|
|
import { prisma } from "~~/server/utils/db";
|
|
import { createApiLogger } from "~~/server/utils/logging";
|
|
import { getRuntimeStats } from "~~/server/utils/runtimeState";
|
|
|
|
/**
|
|
* 运行统计接口
|
|
*
|
|
* 返回进程 uptime、模型名以及当前用户的问答记录总数
|
|
* 必须携带有效 session cookie(由 api-auth middleware 统一鉴权)
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const logger = createApiLogger(event, "api.stats");
|
|
const userId = event.context.auth!.user.id;
|
|
|
|
const [runtimeStats, qa_records_count] = await Promise.all([
|
|
Promise.resolve(getRuntimeStats()),
|
|
prisma.qaRecord.count({ where: { userId } })
|
|
]);
|
|
|
|
logger.info("finish_success");
|
|
return { ...runtimeStats, qa_records_count };
|
|
});
|