picobook/src/server/api/release.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-03-25 00:29:43 -07:00
import { Type } from "@sinclair/typebox";
import { FirRouteInput, FirRouteOptions } from "../util/routewrap.js";
2024-03-25 21:35:58 -07:00
import fs from "fs";
import git from "isomorphic-git";
import http from "isomorphic-git/http/node";
2024-03-25 00:29:43 -07:00
const method = "POST";
2024-03-25 00:42:23 -07:00
const url = "/api/release";
2024-03-25 00:29:43 -07:00
// const payloadT = Type.Object({
// png: Type.String(),
// });
const payloadT = Type.Any();
2024-03-25 21:35:58 -07:00
const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
const {manifest, token} = payload;
if (!fs.existsSync("./repos")) {
fs.mkdirSync("./repos", {recursive: true})
}
2024-03-26 00:13:42 -07:00
console.log(manifest);
console.log("cloning...");
2024-03-25 21:35:58 -07:00
await git.clone({
fs,
http,
2024-03-26 00:20:53 -07:00
// headers: {
// "Authorization": `Bearer ${token}`,
2024-03-26 00:11:20 -07:00
// },
2024-03-26 00:20:53 -07:00
onAuth() {
return {
username: 'x-access-token',
password: token,
}
},
2024-03-25 21:35:58 -07:00
dir: "./repos",
url: manifest.repo,
});
2024-03-26 00:13:42 -07:00
console.log("cloned");
2024-03-25 21:35:58 -07:00
const localManifest = JSON.parse(await fs.promises.readFile("./repos/picobook.json", "utf8"));
2024-03-26 00:13:42 -07:00
console.log("read local manifest");
2024-03-25 21:35:58 -07:00
fs.promises.rm("./repos");
console.log({
manifest,
localManifest,
});
return true;
2024-03-25 00:29:43 -07:00
};
export default {
method,
url,
payloadT,
handler,
} as const satisfies FirRouteOptions<typeof payloadT>;