import { Type } from "@sinclair/typebox"; import { FirRouteInput, FirRouteOptions } from "../util/routewrap.ts"; import { authors } from "../../data/authors.ts"; import { Octokit } from "octokit"; import { decrypt } from "../util/crypt.ts"; const method = "GET"; const url = "/api/author"; const payloadT = Type.Any(); const handler = async ({ payload }: FirRouteInput) => { const { author } = payload; const authorData = authors.find((x) => x.username === author); if (!authorData) { return { author: null, games: [], }; } console.log("author", authorData); const pat = decrypt({ password: process.env.ENCRYPTION_PASSWORD!, cyphertext: authorData.auth.pat, }); const octokit = new Octokit({ auth: pat, }); const gameStuff = await octokit.rest.repos.getContent({ owner: authorData.username, repo: authorData.repo, path: ".picobook", }); // TODO: get the games. const games: string[] = []; if (Array.isArray(gameStuff.data)) { games.push( ...gameStuff.data .map((x) => x.name) .filter((x) => x.endsWith(".p8.png")) .map((x) => x.slice(0, -".p8.png".length)), ); console.log("hi"); } return { author, games, }; }; export default { method, url, payloadT, handler, } as const satisfies FirRouteOptions;