diff --git a/src/database/migrations/4-fourth-migration.sql b/src/database/migrations/4-fourth-migration.sql new file mode 100644 index 0000000..a348f5b --- /dev/null +++ b/src/database/migrations/4-fourth-migration.sql @@ -0,0 +1,13 @@ +DROP TABLE repos; + +DROP TABLE releases; + +CREATE TABLE releases ( + id text, + picobook_version int, + repo text, + slug text, + version text, + carts json, + title text, +); \ No newline at end of file diff --git a/src/server/api/release.ts b/src/server/api/release.ts index cc2c350..071876d 100644 --- a/src/server/api/release.ts +++ b/src/server/api/release.ts @@ -1,4 +1,5 @@ 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"; @@ -13,9 +14,26 @@ 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);