1
0
Fork 0
taevas.xyz/backend/api/infos/gamedev/itchio.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

50 linhas
1,3 KiB
TypeScript

import { headers, parseJson, type Handler } from "../..";
export type Info = {
user: {
name: string
url: string
}
game: {
name: string
description?: string
date: string
url: string
cover_url?: string
}
} | undefined;
export const itchio: Handler = async () => {
/** https://itch.io/docs/api/serverside#reference/profilegames-httpsitchioapi1keymy-games */
const response = await parseJson(await fetch(`https://itch.io/api/1/${process.env["API_ITCHIO"]}/my-games`, {headers})) as {
games: {
published_at?: string
title: string
short_text?: string
url: string
cover_url?: string
user: {
display_name: string
url: string
}
}[];
};
/** Do not show games that are unpublished (a game that is not public; still in development but has a page) */
const published_games = response.games.filter((game) => game.published_at);
const activity: Info = {
user: {
name: published_games[0].user.display_name,
url: published_games[0].user.url
},
game: {
name: published_games[0].title,
description: published_games[0].short_text,
date: published_games[0].published_at!,
url: published_games[0].url,
cover_url: published_games[0].cover_url
}
};
return Response.json(activity, {status: 200});
};