Add authorization header support for API requests

This commit is contained in:
Seth 2025-01-13 13:38:24 -05:00
parent 4769a9e335
commit a9ae1d92b7
No known key found for this signature in database
GPG key ID: 8B7A2C60CDF65CAC

View file

@ -6,9 +6,17 @@ type repo = {
}
type repos = repo[]
const fetchOpts: RequestInit = {}
if (process.env.AuthorizationHeaderToken) {
fetchOpts.headers = {
"Authorization": `Bearer ${process.env.AuthorizationHeaderToken}`
}
}
const getTopLangs = async (type: "users" | "orgs", name: string) => {
const obj: Record<string, number> = {}
const userRepoResp = await fetch(`https://git.creations.works/api/v1/${type}/${name}/repos?limit=0`);
const userRepoResp = await fetch(`https://git.creations.works/api/v1/${type}/${name}/repos?limit=0`, fetchOpts);
const userRepos = await userRepoResp.json() as repos;
for (const repo of userRepos) {