save to db

This commit is contained in:
dylan
2024-03-31 17:33:27 -07:00
parent 8b987bc589
commit 7874167582
6 changed files with 163 additions and 18 deletions

View File

@@ -1,11 +1,12 @@
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";
import { getRelease, insertRelease } from "../dbal/dbal.ts";
import { ManifestType } from "../types.ts";
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const reposPath = path.resolve(__dirname, "..", "..", "..", "repos");
@@ -14,19 +15,6 @@ 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<typeof payloadT>) => {
const {manifest, token} = payload;
@@ -34,6 +22,11 @@ const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
return false;
}
const release = await getRelease({author: manifest.author, slug: manifest.id, version: manifest.version});
if (release) {
return false;
}
const uuid = randomUUID();
const repoPath = path.join(reposPath, uuid);
@@ -45,6 +38,11 @@ const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
const carts = await getCarts(repoPath, manifest.carts);
insertRelease({
manifest,
carts,
});
console.log({
manifest,
carts,