taevas.xyz/netlify/functions/hackthebox.ts

31 lines
812 B
TypeScript
Raw Normal View History

import {type Handler} from "@netlify/functions";
import {api} from "./shared/api.js";
import {type HacktheboxInfo} from "../../src/components/Info/Hackthebox.js";
2023-05-08 03:00:11 +02:00
2023-11-05 21:01:24 +01:00
const handler: Handler = async () => {
const hackthebox: {profile: {activity: HacktheboxInfo[]}} = await api<{
2023-05-08 03:00:11 +02:00
profile: {
activity: HacktheboxInfo[];
};
2023-05-08 03:00:11 +02:00
}>
("https://www.hackthebox.com/api/v4/profile/activity/1063999");
2023-05-08 03:00:11 +02:00
const pwn = hackthebox.profile.activity.find((a: HacktheboxInfo) => a!.object_type === "machine");
2023-05-08 03:00:11 +02:00
if (!pwn) {
return {
statusCode: 404,
body: "",
};
2023-05-08 03:00:11 +02:00
}
pwn.machine_avatar = `https://www.hackthebox.com${pwn.machine_avatar}`;
pwn.date = pwn.date.substring(0, pwn.date.indexOf("T"));
2023-05-08 03:00:11 +02:00
return {
statusCode: 200,
body: JSON.stringify(pwn),
};
};
2023-05-08 03:00:11 +02:00
export {handler};