mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-19 14:17:20 +02:00
fix: read public repositories without scoped App token minting
This commit is contained in:
5 files changed
+97
-70
No files matched your search
@@ -1,12 +1,16 @@
|
||||
import { createHash } from "crypto";
|
||||
|
||||
interface TokenContext { quotaKey: string; renew: (force?: boolean) => Promise<string>; }
|
||||
interface TokenContext { quotaKey: string; renew: (force?: boolean) => Promise<string>; publicRepository?: string; }
|
||||
const contexts = new Map<string, TokenContext>();
|
||||
export function registerGitHubToken(token: string, context: TokenContext) {
|
||||
if (contexts.size >= 2000 && !contexts.has(token)) contexts.delete(contexts.keys().next().value!);
|
||||
contexts.set(token, context);
|
||||
}
|
||||
export function githubTokenContext(token: string) { return contexts.get(token); }
|
||||
export function githubTokenContext(token: string) {
|
||||
const context = contexts.get(token);
|
||||
if (!context && token.startsWith("public-read:")) throw new Error("Public repository access context expired");
|
||||
return context;
|
||||
}
|
||||
export function githubQuotaKey(token: string) {
|
||||
return contexts.get(token)?.quotaKey || createHash("sha256").update(token).digest("hex").slice(0, 24);
|
||||
}
|
||||
Reference in new issue
Block a user