50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { Type } from "@sinclair/typebox";
|
|
import { FirRouteInput, FirRouteOptions } from "../util/routewrap.js";
|
|
import fs from "fs";
|
|
import git from "isomorphic-git";
|
|
import http from "isomorphic-git/http/node";
|
|
|
|
const method = "POST";
|
|
const url = "/api/release";
|
|
|
|
// const payloadT = Type.Object({
|
|
// png: Type.String(),
|
|
// });
|
|
|
|
const payloadT = Type.Any();
|
|
|
|
const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
|
|
const {manifest, token} = payload;
|
|
if (!fs.existsSync("./repos")) {
|
|
fs.mkdirSync("./repos", {recursive: true})
|
|
}
|
|
await git.clone({
|
|
fs,
|
|
http,
|
|
// headers: {
|
|
// "Authorization": `token ${token}`,
|
|
// },
|
|
onAuth() {
|
|
return {
|
|
username: token,
|
|
password: 'x-access-token',
|
|
}
|
|
},
|
|
dir: "./repos",
|
|
url: manifest.repo,
|
|
});
|
|
const localManifest = JSON.parse(await fs.promises.readFile("./repos/picobook.json", "utf8"));
|
|
fs.promises.rm("./repos");
|
|
console.log({
|
|
manifest,
|
|
localManifest,
|
|
});
|
|
return true;
|
|
};
|
|
|
|
export default {
|
|
method,
|
|
url,
|
|
payloadT,
|
|
handler,
|
|
} as const satisfies FirRouteOptions<typeof payloadT>; |