feat: implemented a basic store and emulatorjs
This commit is contained in:
parent
2f32cbc730
commit
7286541822
121 changed files with 5900 additions and 1092 deletions
|
|
@ -1,17 +1,18 @@
|
|||
import Elysia, { status } from "elysia";
|
||||
import { getPlatformApiPlatformsIdGet, getPlatformsApiPlatformsGet, getRomsApiRomsGet } from "@clients/romm";
|
||||
import z from "zod";
|
||||
import { count, eq, getTableColumns, notInArray } from "drizzle-orm";
|
||||
import { count, eq, getTableColumns } from "drizzle-orm";
|
||||
import { db } from "../app";
|
||||
import { FrontEndPlatformType } from "@shared/constants";
|
||||
import * as schema from "../schema/app";
|
||||
import * as schema from "@schema/app";
|
||||
import { CACHE_KEYS, getOrCached } from "../cache";
|
||||
|
||||
export default new Elysia()
|
||||
.get('/platforms', async () =>
|
||||
{
|
||||
const platforms: FrontEndPlatformType[] = [];
|
||||
let rommPlatformsSet: Set<string> | undefined;
|
||||
const { data: rommPlatforms } = await getPlatformsApiPlatformsGet();
|
||||
const rommPlatforms = await getOrCached(CACHE_KEYS.ROM_PLATFORMS, () => getPlatformsApiPlatformsGet({ throwOnError: true }), { expireMs: 60 * 60 * 1000 }).then(d => d.data).catch(e => console.error(e));
|
||||
|
||||
const localPlatforms = await db.select({ ...getTableColumns(schema.platforms), game_count: count(schema.games.id) })
|
||||
.from(schema.platforms)
|
||||
|
|
@ -32,7 +33,7 @@ export default new Elysia()
|
|||
path_cover: `/api/romm/image/romm/assets/platforms/${p.slug}.svg`,
|
||||
game_count: p.rom_count,
|
||||
updated_at: new Date(p.updated_at),
|
||||
id: { source: 'romm', id: p.id },
|
||||
id: { source: 'romm', id: String(p.id) },
|
||||
hasLocal: localPlatformSet.has(p.slug),
|
||||
paths_screenshots: game.data?.items[0]?.merged_screenshots.map(s => `/api/romm/image/romm/${s}`) ?? []
|
||||
};
|
||||
|
|
@ -46,7 +47,13 @@ export default new Elysia()
|
|||
|
||||
platforms.push(...await Promise.all(localPlatforms.filter(p => !rommPlatformsSet?.has(p.slug)).map(async p =>
|
||||
{
|
||||
const game = await db.query.games.findFirst({ where: eq(schema.games.platform_id, p.id), with: { screenshots: true }, columns: {} });
|
||||
const game = await db.query.games.findFirst({ where: eq(schema.games.platform_id, p.id) });
|
||||
let screenshots: { id: number; }[] = [];
|
||||
if (game)
|
||||
{
|
||||
screenshots = await db.query.screenshots.findMany({ where: eq(schema.screenshots.game_id, game.id), columns: { id: true } });
|
||||
}
|
||||
|
||||
const platform: FrontEndPlatformType = {
|
||||
slug: p.slug,
|
||||
name: p.name,
|
||||
|
|
@ -54,9 +61,9 @@ export default new Elysia()
|
|||
path_cover: `/api/romm/platform/local/${p.id}/cover`,
|
||||
game_count: p.game_count,
|
||||
updated_at: p.created_at,
|
||||
id: { source: 'local', id: p.id },
|
||||
id: { source: 'local', id: String(p.id) },
|
||||
hasLocal: true,
|
||||
paths_screenshots: game?.screenshots?.map(s => `/api/romm/screenshot/${s.id}`) ?? []
|
||||
paths_screenshots: screenshots?.map(s => `/api/romm/screenshot/${s.id}`) ?? []
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -66,13 +73,52 @@ export default new Elysia()
|
|||
return { platforms };
|
||||
}).get('/platforms/:source/:id', async ({ params: { source, id } }) =>
|
||||
{
|
||||
const rommPlatform = await getPlatformApiPlatformsIdGet({ path: { id } });
|
||||
if (rommPlatform.data)
|
||||
if (source === 'romm')
|
||||
{
|
||||
return rommPlatform.data;
|
||||
const { data: rommPlatform, response } = await getPlatformApiPlatformsIdGet({ path: { id } });
|
||||
if (rommPlatform)
|
||||
{
|
||||
const platform: FrontEndPlatformType = {
|
||||
slug: rommPlatform.slug,
|
||||
name: rommPlatform.display_name,
|
||||
family_name: rommPlatform.family_name,
|
||||
path_cover: `/api/romm/image/romm/assets/platforms/${rommPlatform.slug}.svg`,
|
||||
game_count: rommPlatform.rom_count,
|
||||
updated_at: new Date(rommPlatform.updated_at),
|
||||
id: { source: 'romm', id: String(rommPlatform.id) },
|
||||
paths_screenshots: [],
|
||||
hasLocal: false
|
||||
};
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
return status("Not Found", response);
|
||||
}
|
||||
else if (source === 'local')
|
||||
{
|
||||
const localPlatform = await db.query.platforms.findFirst({ where: eq(schema.platforms.id, id) });
|
||||
if (localPlatform)
|
||||
{
|
||||
const platform: FrontEndPlatformType = {
|
||||
slug: localPlatform.slug,
|
||||
name: localPlatform.name,
|
||||
family_name: localPlatform.family_name,
|
||||
path_cover: `/api/romm/platform/local/${localPlatform.id}/cover`,
|
||||
game_count: 0,
|
||||
updated_at: localPlatform.created_at,
|
||||
id: { source: 'local', id: String(localPlatform.id) },
|
||||
hasLocal: true,
|
||||
paths_screenshots: []
|
||||
};
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
return status("Not Found");
|
||||
}
|
||||
|
||||
return status("Not Found", rommPlatform.response);
|
||||
return status("Not Implemented");
|
||||
}, { params: z.object({ source: z.string(), id: z.coerce.number() }) }).get('/platform/local/:id/cover', async ({ params: { id }, set }) =>
|
||||
{
|
||||
const coverBlob = await db.query.platforms.findFirst({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue