display cart images

This commit is contained in:
Dylan Pizzo
2026-06-14 22:23:37 -04:00
parent 19e0ae4605
commit f3d84f3c55
4 changed files with 90 additions and 12 deletions
+56
View File
@@ -0,0 +1,56 @@
import { Octokit } from "octokit";
import { decrypt } from "./crypt";
import { authors } from "../../data/authors";
type Game = { carts: { name: string; src: string }[] };
const gameCache: Record<string, Game> = {};
export const getGame = async (
author: string,
name: string,
): Promise<Game | null> => {
const authorData = authors.find((x) => x.username === author);
if (!authorData) {
return null;
}
const pat = decrypt({
password: process.env.ENCRYPTION_PASSWORD!,
cyphertext: authorData.auth.pat,
});
const octokit = new Octokit({
auth: pat,
});
const gameData = (
await octokit.rest.repos.getContent({
owner: authorData.username,
repo: authorData.repo,
path: `.picobook/${name}.p8.png`,
})
).data;
if (Array.isArray(gameData)) {
return null;
}
if (gameData.type !== "file") {
return null;
}
if (!(gameData.sha in gameCache)) {
gameCache[gameData.sha] = {
carts: [{ name, src: `data:image/png;base64,${gameData.content}` }],
};
}
return gameCache[gameData.sha];
};
export const getGameFromSha = async (sha: string): Promise<Game | null> => {
if (gameCache[sha]) {
console.log("cache hit");
}
return gameCache[sha] ?? null;
};
+1
View File
@@ -0,0 +1 @@
export type Game = { carts: { name: string; src: string }[] };