taevas.xyz/netlify/functions/github.ts
Taevas 719672ffa0 Load an Info's Website separately from the Info itself
Makes it so:
- An `Info`'s `Website` doesn't need to wait for other `Website`s of that same `Info` to load to show up
- An `Info`s `Website` not working won't prevent other `Website`s of that same `Info` from showing up
- Code is more split and organized

Furthermore, the token for the osu! API is now stored, and used for ALL osu! requests for 24 hours instead of being revoked

Overall, it's a lot of future-proofing so things on working even if I'm no longer there to maintain them
Also so `Info`s can be added, changed, and removed more easily
2024-05-04 19:14:18 +02:00

28 lines
1,023 B
TypeScript

import {type Handler} from "@netlify/functions";
import {Octokit} from "@octokit/rest";
import {type GithubInfo} from "../../src/components/Info/Coding/GitHub.js";
const handler: Handler = async () => {
const octokit = new Octokit({auth: process.env.API_GITHUB});
const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username: "TTTaevas"});
const publicPush = github.data.find((e) => e.type === "PushEvent" && e.public);
const privatePush = github.data.find((e) => e.type === "PushEvent" && !e.public);
const info: GithubInfo = {
public: publicPush ? {
repo: publicPush.repo.name,
date: publicPush.created_at ? publicPush.created_at.substring(0, publicPush.created_at.indexOf("T")) : "",
} : undefined,
private: privatePush ? {
date: privatePush.created_at ? privatePush.created_at.substring(0, privatePush.created_at.indexOf("T")) : "",
} : undefined,
};
return {
statusCode: 200,
body: JSON.stringify(info),
};
};
export {handler};