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