1
0
Fork 0
taevas.xyz/backend/api/infos/hacking/hackthebox.ts
Taevas d781f7138f
Make backend/frontend distinction clearer
Helps with eventually adding other pages
Also makes it clear it's the backend that decides what data to send to the frontend
2025-07-08 14:40:35 +02:00

32 linhas
935 B
TypeScript

import { headers, parseJson, type Handler } from "../..";
export type Info = {
id: string;
date_diff: string;
date: string;
object_type: string;
type: string;
name: string;
machine_avatar: string;
} | undefined;
const user_id = 1063999;
export const hackthebox: Handler = async () => {
/** https://documenter.getpostman.com/view/13129365/TVeqbmeq#1b0b22fc-2e45-456a-9a8f-42888375d1a9 */
const hackthebox = await parseJson(await fetch(`https://www.hackthebox.com/api/v4/profile/activity/${user_id}`, {headers})) as {
profile: {
activity: Info[];
};
};
const pwn = hackthebox.profile.activity.find((a: Info) => a?.object_type === "machine");
if (!pwn) {
return new Response("Not Found", {status: 404});
}
pwn.machine_avatar = `https://www.hackthebox.com${pwn.machine_avatar}`;
pwn.date = pwn.date.substring(0, pwn.date.indexOf("T"));
return Response.json(pwn, {status: 200});
};