feat: 加固标题抓取并加上限流与可选入站令牌
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { logStore } from "./store.js";
|
||||
import { checkToken, configuredToken } from "../utils/auth.js";
|
||||
|
||||
const PANEL_HTML = `<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
@@ -238,6 +239,19 @@ init();
|
||||
|
||||
export async function adminRoutes(app: FastifyInstance): Promise<void> {
|
||||
|
||||
// 管理面板会展示完整 prompt 与学习内容,与 /ai/* 共用同一个可选令牌(安全-03)
|
||||
if (!configuredToken()) {
|
||||
app.log.warn(
|
||||
"未设置 LPT_AI_TOKEN,/admin 面板与 /ai/* 无访问保护(面板会展示 prompt 与学习内容)",
|
||||
);
|
||||
}
|
||||
|
||||
app.addHook("preHandler", async (request, reply) => {
|
||||
if (!checkToken(request, reply)) {
|
||||
return reply;
|
||||
}
|
||||
});
|
||||
|
||||
// —— 面板页面 ——
|
||||
app.get("/admin", async (_request, reply) => {
|
||||
return reply.type("text/html; charset=utf-8").send(PANEL_HTML);
|
||||
|
||||
Reference in New Issue
Block a user