new format wip
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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/game";
|
||||
|
||||
const payloadT = Type.Any();
|
||||
|
||||
const handler = async ({ payload }: FirRouteInput<typeof payloadT>) => {
|
||||
const { author, name } = payload;
|
||||
|
||||
const authorData = authors.find((x) => x.username === author);
|
||||
|
||||
if (!authorData) {
|
||||
return null;
|
||||
}
|
||||
console.log("author", authorData);
|
||||
|
||||
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;
|
||||
|
||||
console.log(gameData);
|
||||
|
||||
if (Array.isArray(gameData)) {
|
||||
return null;
|
||||
}
|
||||
if (gameData.type !== "file") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
carts: [{ src: `data:image/png;base64,${gameData.content}` }],
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
method,
|
||||
url,
|
||||
payloadT,
|
||||
handler,
|
||||
} as const satisfies FirRouteOptions<typeof payloadT>;
|
||||
Reference in New Issue
Block a user