2024-04-02 19:04:34 -07:00
|
|
|
import { Type } from "@sinclair/typebox";
|
|
|
|
|
import { FirRouteInput, FirRouteOptions } from "../util/routewrap.ts";
|
2026-06-10 21:47:30 -04:00
|
|
|
import { authors } from "../../data/authors.ts";
|
|
|
|
|
import { Octokit } from "octokit";
|
|
|
|
|
import { decrypt } from "../util/crypt.ts";
|
2024-04-02 19:04:34 -07:00
|
|
|
|
|
|
|
|
const method = "GET";
|
|
|
|
|
const url = "/api/author";
|
|
|
|
|
|
|
|
|
|
const payloadT = Type.Any();
|
|
|
|
|
|
2026-06-10 21:47:30 -04:00
|
|
|
const handler = async ({ payload }: FirRouteInput<typeof payloadT>) => {
|
|
|
|
|
const { author } = payload;
|
2024-04-02 19:04:34 -07:00
|
|
|
|
2026-06-10 21:47:30 -04:00
|
|
|
const authorData = authors.find((x) => x.username === author);
|
|
|
|
|
|
|
|
|
|
if (!authorData) {
|
2024-04-02 19:04:34 -07:00
|
|
|
return {
|
|
|
|
|
author: null,
|
2026-06-10 21:47:30 -04:00
|
|
|
games: [],
|
2024-04-02 19:04:34 -07:00
|
|
|
};
|
|
|
|
|
}
|
2026-06-10 21:47:30 -04:00
|
|
|
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");
|
|
|
|
|
}
|
2024-04-02 19:04:34 -07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
author,
|
|
|
|
|
games,
|
2026-06-10 21:47:30 -04:00
|
|
|
};
|
2024-04-02 19:04:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
method,
|
|
|
|
|
url,
|
|
|
|
|
payloadT,
|
|
|
|
|
handler,
|
2026-06-10 21:47:30 -04:00
|
|
|
} as const satisfies FirRouteOptions<typeof payloadT>;
|