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
34 lines
946 B
TypeScript
34 lines
946 B
TypeScript
import {type Handler} from "@netlify/functions";
|
|
import fetch from "node-fetch";
|
|
import {type GitlabInfo} from "../../src/components/Info/Coding/GitLab.js";
|
|
|
|
const handler: Handler = async () => {
|
|
const gitlab = await fetch("https://gitlab.com/api/v4/events?action=pushed", {
|
|
method: "GET",
|
|
headers: {
|
|
"PRIVATE-TOKEN": process.env.API_GITLAB!,
|
|
"Content-Type": "application/json",
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
"Accept": "application/json",
|
|
},
|
|
});
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
const {created_at} = (await gitlab.json() as Record<string, any>)[0];
|
|
if (typeof created_at !== "string") {
|
|
return {
|
|
statusCode: 404,
|
|
};
|
|
}
|
|
|
|
const activity: GitlabInfo = {
|
|
date: created_at.substring(0, created_at.indexOf("T")),
|
|
};
|
|
|
|
return {
|
|
statusCode: 200,
|
|
body: JSON.stringify(activity),
|
|
};
|
|
};
|
|
|
|
export {handler};
|