perf: 去掉 handler 内层重复鉴权
鉴权只保留各路由 r.use 一次,受保护请求少一轮会话查库。
This commit is contained in:
@@ -43,8 +43,6 @@ export function adminAuditRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const q = c.req.query();
|
||||
const page = Math.max(1, Number(q.page ?? 1) || 1);
|
||||
const page_size = Math.min(
|
||||
|
||||
@@ -31,8 +31,6 @@ export function adminEngineRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
return c.json(engineStatus, 200);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -73,8 +73,6 @@ export function adminKeyRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const q = c.req.query();
|
||||
const filter: {
|
||||
member_id?: number | "unassigned";
|
||||
@@ -129,8 +127,6 @@ export function adminKeyRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const body = await c.req.json().catch(() => null);
|
||||
const sk_key = typeof body?.sk_key === "string" ? body.sk_key.trim() : "";
|
||||
let member_id: number | null = null;
|
||||
@@ -264,8 +260,6 @@ export function adminKeyRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const id = Number(c.req.param("id"));
|
||||
const body = await c.req.json().catch(() => null);
|
||||
const repos = c.get("repos");
|
||||
|
||||
@@ -53,8 +53,6 @@ export function adminMemberRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const repos = c.get("repos");
|
||||
const rows = await repos.members.listAll();
|
||||
const items = [];
|
||||
@@ -90,8 +88,6 @@ export function adminMemberRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const body = await c.req.json().catch(() => null);
|
||||
const name = typeof body?.name === "string" ? body.name.trim() : "";
|
||||
const remark = typeof body?.remark === "string" ? body.remark : "";
|
||||
@@ -160,8 +156,6 @@ export function adminMemberRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const id = Number(c.req.param("id"));
|
||||
const body = await c.req.json().catch(() => null);
|
||||
const status = body?.status;
|
||||
@@ -203,8 +197,6 @@ export function adminMemberRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const id = Number(c.req.param("id"));
|
||||
const repos = c.get("repos");
|
||||
const before = await repos.members.findById(id);
|
||||
|
||||
@@ -122,8 +122,6 @@ export function adminPaymentRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const repos = c.get("repos");
|
||||
const timeline = resolveQpuTimeline(await repos.qpu.listTimeline());
|
||||
const rows = await repos.payments.listAll();
|
||||
@@ -164,8 +162,6 @@ export function adminPaymentRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const body = (await c.req.json().catch(() => ({}))) as Record<
|
||||
string,
|
||||
unknown
|
||||
@@ -221,8 +217,6 @@ export function adminPaymentRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const id = Number(c.req.param("id"));
|
||||
const body = (await c.req.json().catch(() => ({}))) as Record<
|
||||
string,
|
||||
@@ -274,8 +268,6 @@ export function adminPaymentRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const id = Number(c.req.param("id"));
|
||||
const repos = c.get("repos");
|
||||
const before = await repos.payments.findById(id);
|
||||
|
||||
@@ -216,8 +216,6 @@ export function adminSessionRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
return c.json({ username: c.get("adminUsername") ?? "" }, 200);
|
||||
},
|
||||
);
|
||||
@@ -235,8 +233,6 @@ export function adminSessionRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const token = getCookie(c, SESSION_COOKIE);
|
||||
if (token) {
|
||||
await c.get("repos").sessions.deleteByTokenHash(await hashToken(token));
|
||||
@@ -267,8 +263,6 @@ export function adminSessionRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const body = await c.req.json().catch(() => null);
|
||||
const old_password = String(body?.old_password ?? "");
|
||||
const new_password = String(body?.new_password ?? "");
|
||||
|
||||
@@ -103,8 +103,6 @@ export function adminUsageRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const latest = await c.get("repos").qpu.latest();
|
||||
if (!latest) {
|
||||
return c.json(
|
||||
@@ -142,8 +140,6 @@ export function adminUsageRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const q = c.req.query();
|
||||
const range = parseRange(q);
|
||||
if ("fields" in range) {
|
||||
@@ -299,8 +295,6 @@ export function adminUsageRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireAdminSession(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const q = c.req.query();
|
||||
const range = parseRange(q);
|
||||
if ("fields" in range) {
|
||||
|
||||
@@ -60,8 +60,6 @@ export function memberViewRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireMemberToken(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const row = await c.get("repos").members.findById(c.get("memberId")!);
|
||||
if (!row) return jsonError(c, 401, ERR.session_expired());
|
||||
return c.json({ id: row.id, name: row.name }, 200);
|
||||
@@ -90,8 +88,6 @@ export function memberViewRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireMemberToken(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const range = parseRange(c.req.query());
|
||||
if ("fields" in range) {
|
||||
return jsonError(c, 422, ERR.validation_failed(range.fields));
|
||||
@@ -249,8 +245,6 @@ export function memberViewRoutes() {
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const guard = await requireMemberToken(c, async () => {});
|
||||
if (guard) return guard;
|
||||
const q = c.req.query();
|
||||
const range = parseRange(q);
|
||||
if ("fields" in range) {
|
||||
|
||||
Reference in New Issue
Block a user