Merge branch 'main' into dev

This commit is contained in:
dylan 2024-03-31 18:06:11 -07:00
commit 03ea59c7e3
4 changed files with 23 additions and 10 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE releases DROP COLUMN created_at;
ALTER TABLE releases ADD created_at timestamp;

View File

@ -38,7 +38,7 @@ const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
const carts = await getCarts(repoPath, manifest.carts); const carts = await getCarts(repoPath, manifest.carts);
insertRelease({ await insertRelease({
manifest, manifest,
carts, carts,
}); });

View File

@ -1,9 +1,7 @@
// Database Access Layer stuff goes here // Database Access Layer stuff goes here
// Database Access Layer stuff goes here
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { db, sql } from "../../database/db" import { db, sql } from "../../database/db";
import { JsonValue } from '@firebox/tsutil';
import { PicobookManifest } from '../types'; import { PicobookManifest } from '../types';
export type DbRelease = { export type DbRelease = {
@ -16,6 +14,16 @@ export type DbRelease = {
manifest: PicobookManifest; manifest: PicobookManifest;
} }
export type DbReleaseInternal = {
id: string;
slug: string;
repo: string;
version: string;
carts: {carts: {name: string; rom: number[]}[]};
author: string;
manifest: PicobookManifest;
}
const compareVersions = (a: string, b: string) => { const compareVersions = (a: string, b: string) => {
const [a1, a2] = a.split(".").map(x => Number(x)); const [a1, a2] = a.split(".").map(x => Number(x));
const [b1, b2] = b.split(".").map(x => Number(x)); const [b1, b2] = b.split(".").map(x => Number(x));
@ -34,24 +42,24 @@ export const getReleases = async (where: {
version?: string; version?: string;
}): Promise<DbRelease[]> => { }): Promise<DbRelease[]> => {
const {author, slug, version} = where; const {author, slug, version} = where;
let rows: DbReleaseInternal[];
if (!version) { if (!version) {
const rows = await db.query(sql` rows = await db.query(sql`
SELECT * from releases SELECT * from releases
WHERE WHERE
slug = ${slug} AND slug = ${slug} AND
author = ${author} author = ${author}
`); `);
return rows;
} else { } else {
const rows = await db.query(sql` rows = await db.query(sql`
SELECT * from releases SELECT * from releases
WHERE WHERE
slug = ${slug} AND slug = ${slug} AND
author = ${author} AND author = ${author} AND
version = ${version} version = ${version}
`); `);
return rows;
} }
return rows.map(row => ({...row, carts: row.carts.carts}));
} }
export const getRelease = async (where: { export const getRelease = async (where: {
@ -78,12 +86,13 @@ export const getRelease = async (where: {
export const insertRelease = async (props: {manifest: PicobookManifest, carts: {name: string; rom: number[]}[]}) => { export const insertRelease = async (props: {manifest: PicobookManifest, carts: {name: string; rom: number[]}[]}) => {
const {manifest, carts} = props; const {manifest, carts} = props;
// console.log('carts', JSON.stringify(carts));
const {id: slug, author, repo, version} = manifest; const {id: slug, author, repo, version} = manifest;
const id = uuidv4(); const id = uuidv4();
const now = new Date(); const now = new Date();
await db.query(sql` await db.query(sql`
INSERT INTO chats (id, slug, repo, version, author, carts, manifest, created_at) INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at)
VALUES (${id}, ${slug}, ${repo}, ${version}, ${author} ${carts}, ${manifest}, ${now}) VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${{carts}}, ${manifest}, ${now})
`); `);
return id; return id;
} }

View File

@ -1,4 +1,5 @@
import echo from "./api/echo.ts"; import echo from "./api/echo.ts";
import getRelease from "./api/getRelease.ts";
import release from "./api/release.ts"; import release from "./api/release.ts";
import webhook from "./api/webhook.ts"; import webhook from "./api/webhook.ts";
@ -6,6 +7,7 @@ export const routeList = [
echo, echo,
webhook, webhook,
release, release,
getRelease,
]; ];
export type RouteList = typeof routeList; export type RouteList = typeof routeList;