import { Type } from "@sinclair/typebox"; import { TypeCompiler } from "@sinclair/typebox/compiler"; import { FirRouteInput, FirRouteOptions } from "../util/routewrap"; import {git} from "../util/git.ts"; import { randomUUID } from "crypto"; import path from "path"; import {fileURLToPath} from 'url'; import { getCarts } from "../util/carts.ts"; const __dirname = fileURLToPath(new URL('.', import.meta.url)); const reposPath = path.resolve(__dirname, "..", "..", "..", "repos"); const method = "POST"; const url = "/api/release"; const payloadT = Type.Any(); const manifestT = Type.Object({ picobook_version: Type.Number(), id: Type.String(), version: Type.String(), carts: Type.Array(Type.String()), repo: Type.String(), title: Type.Optional(Type.String()), author: Type.Optional(Type.String()), readme: Type.Optional(Type.String()), }); const ManifestType = TypeCompiler.Compile(manifestT) const handler = async ({payload}: FirRouteInput) => { const {manifest, token} = payload; if (!ManifestType.Check(manifest)) { return false; } const uuid = randomUUID(); const repoPath = path.join(reposPath, uuid); await git.clone({ from: manifest.repo, to: repoPath, auth: token, }); const carts = await getCarts(repoPath, manifest.carts); console.log({ manifest, carts, }); return true; }; export default { method, url, payloadT, handler, } as const satisfies FirRouteOptions;