MCPcopy Create free account
hub / github.com/PIKACHUIM/CFWorkerACME / parseAuth

Function parseAuth

src/routes/openapi.ts:33–51  ·  view source on GitHub ↗

解析鉴权头

(c: Context)

Source from the content-addressed store, hash-verified

31
32/** 解析鉴权头 */
33function parseAuth(c: Context): { mail: string; token: string } | null {
34 let mail = c.req.header("X-API-Mail") ?? "";
35 let token = c.req.header("X-API-Token") ?? "";
36 if (!mail || !token) {
37 const auth = c.req.header("Authorization") ?? "";
38 if (auth.startsWith("Bearer ")) {
39 const body = auth.slice(7).trim();
40 const idx = body.indexOf(":");
41 if (idx > 0) {
42 mail = body.slice(0, idx);
43 token = body.slice(idx + 1);
44 }
45 }
46 }
47 mail = mail.trim().toLowerCase();
48 token = token.trim();
49 if (!mail || !token) return null;
50 return {mail, token};
51}
52
53/** 内存限流器:Map<mail, { count, resetAt }> */
54const RATE_BUCKET = new Map<string, { count: number; resetAt: number }>();

Callers 1

apiAuthMiddlewareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected