Files
SnowLuma/.pnpm-store/v11/files/d2/e1fab81b77b2e9981fe69406baea5ef99bc3ba978f490665868326a4d8060611ad2a5e88228cfc7e1647fe9ae5a456fd8ef37116395296e77e2bf851db9d1f
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

21 lines
613 B
Plaintext

import { decodeBase64 } from "./encode.js";
//#region src/utils/basic-auth.ts
const CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
const USER_PASS_REGEXP = /^([^:]*):(.*)$/;
const utf8Decoder = new TextDecoder();
const auth = (req) => {
const match = CREDENTIALS_REGEXP.exec(req.headers.get("Authorization") || "");
if (!match) return;
let userPass = void 0;
try {
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode(decodeBase64(match[1])));
} catch {}
if (!userPass) return;
return {
username: userPass[1],
password: userPass[2]
};
};
//#endregion
export { auth };