feat: Implemented AppImage building

This commit is contained in:
Simeon Radivoev 2026-03-01 15:35:07 +02:00
parent d8f471dadc
commit 6a288f765e
38 changed files with 1036 additions and 147 deletions

View file

@ -8,7 +8,7 @@ import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import { drizzle } from "drizzle-orm/bun-sqlite";
import Conf from "conf";
import projectPackage from '~/package.json';
import { Notification, SERVER_URL, SettingsSchema, SettingsType } from "@shared/constants";
import { Notification, SettingsSchema, SettingsType } from "@shared/constants";
import { client } from "@clients/romm/client.gen";
import * as schema from "./schema/app";
import * as emulatorSchema from "./schema/emulators";
@ -18,14 +18,17 @@ import os from 'node:os';
import { ActiveGame } from "../types/types";
import EventEmitter from "node:events";
import { ErrorLike } from "bun";
import { getErrorMessage } from "../utils";
import { appPath, getErrorMessage } from "../utils";
import { DrizzleSqliteDODatabase } from "drizzle-orm/durable-sqlite";
export const config = new Conf<SettingsType>({
projectName: projectPackage.name,
projectSuffix: 'bun',
schema: Object.fromEntries(Object.entries(SettingsSchema.shape).map(([key, schema]) => [key, schema.toJSONSchema() as any])) as any,
defaults: SettingsSchema.parse({}),
defaults: SettingsSchema.parse({
downloadPath: path.join(os.homedir(), "gameflow"),
windowSize: { width: 1280, height: 800 }
} satisfies SettingsType),
});
export const customEmulators = new Conf<Record<string, string>>({
projectName: projectPackage.name,
@ -41,6 +44,7 @@ export const customEmulators = new Conf<Record<string, string>>({
console.log("Config Path Located At: ", config.path);
console.log("Custom Emulator Paths Located At: ", customEmulators.path);
console.log("App Directory is ", process.env.APPDIR);
const fileCookieStore = new FileCookieStore(path.join(path.dirname(config.path), 'cookies.json'));
console.log("Cookie Jar Path Located At: ", fileCookieStore.filePath);
export const jar = new CookieJar(fileCookieStore);
@ -48,8 +52,8 @@ await fs.mkdir(config.get('downloadPath'), { recursive: true });
let sqlite: Database;
export let db: DrizzleSqliteDODatabase<typeof schema>;
await reloadDatabase();
migrate(db!, { migrationsFolder: "./drizzle" });
const emulatorsSqlite = new Database(`./vendors/es-de/emulators.${os.platform()}.${os.arch()}.sqlite`, { readonly: true });
migrate(db!, { migrationsFolder: appPath("./drizzle") });
const emulatorsSqlite = new Database(appPath(`./vendors/es-de/emulators.${os.platform()}.${os.arch()}.sqlite`), { readonly: true });
export const emulatorsDb = drizzle(emulatorsSqlite, { schema: emulatorSchema });
export const taskQueue = new TaskQueue();
config.onDidChange('rommAddress', v => client.setConfig({ baseUrl: v }));

View file

@ -13,10 +13,40 @@ import buildStatusResponse, { getValidLaunchCommandsForGame } from "./services/s
import { errorToResponse } from "elysia/adapter/bun/handler";
import { launchCommand } from "./services/launchGameService";
import { getErrorMessage } from "@/bun/utils";
import sharp from 'sharp';
import { Jimp } from 'jimp';
async function processImage (img: string | Buffer | ArrayBuffer, { blur, width, height }: { blur?: number, width?: number, height?: number; })
{
if (blur)
{
const jimp = await Jimp.read(img);
if (width)
{
jimp.resize({ w: width, h: height });
}
if (height)
{
jimp.resize({ w: width, h: height });
}
if (blur)
{
jimp.blur(blur);
}
return jimp.getBuffer('image/png');
}
if (typeof img === 'string')
{
const rommFetch = await fetch(img);
return rommFetch;
}
return img;
}
export default new Elysia()
.get('/game/local/:id/cover', async ({ params: { id }, query: { blur, width, height }, set }) =>
.get('/game/local/:id/cover', async ({ params: { id }, query, set }) =>
{
const coverBlob = await db.query.games.findFirst({ columns: { cover: true, cover_type: true }, where: eq(schema.games.id, id) });
if (!coverBlob || !coverBlob.cover)
@ -28,22 +58,32 @@ export default new Elysia()
set.headers["content-type"] = coverBlob.cover_type;
}
return sharp(coverBlob.cover).resize({ width, height, withoutEnlargement: true }).blur(blur);
return processImage(coverBlob.cover, query);
/*return sharp(coverBlob.cover)
.resize({ width, height, withoutEnlargement: true })
.blur(blur)
.toBuffer();*/
}, {
params: z.object({ id: z.coerce.number() }),
query: z.object({ blur: z.coerce.number().optional(), width: z.coerce.number().optional(), height: z.coerce.number().optional() })
})
.get('/image/:source/*', async ({ params: { source, "*": path }, query: { blur, width, height } }) =>
.get('/image/:source/*', async ({ params: { source, "*": path }, query }) =>
{
if (source === 'romm')
{
const rommAdress = config.get('rommAddress');
return processImage(`${rommAdress}/${path}`, query);
/*
const rommFetch = await fetch(`${rommAdress}/${path}`);
return sharp(await rommFetch.arrayBuffer()).resize({ width, height, withoutEnlargement: true }).sharpen().blur(blur);
return sharp(await rommFetch.arrayBuffer())
.resize({ width, height, withoutEnlargement: true })
.blur(blur)
.toBuffer();*/
}
return status('Not Found');
}, { query: z.object({ blur: z.coerce.number().optional(), width: z.coerce.number().optional(), height: z.coerce.number().optional() }) })
.get('/screenshot/:id', async ({ params: { id }, query: { blur, width, height }, set }) =>
.get('/screenshot/:id', async ({ params: { id }, query, set }) =>
{
const screenshot = await db.query.screenshots.findFirst({ where: eq(schema.screenshots.id, id), columns: { content: true, type: true } });
if (screenshot)
@ -52,8 +92,10 @@ export default new Elysia()
{
set.headers["content-type"] = screenshot.type;
}
return sharp(screenshot.content).resize({ width, height, withoutEnlargement: true }).blur(blur);
return processImage(screenshot.content, query);
//return sharp(screenshot.content).resize({ width, height, withoutEnlargement: true }).blur(blur).toBuffer();
//return screenshot.content;
}
return status(404);
@ -158,7 +200,7 @@ export default new Elysia()
paths_screenshots: localGame.screenshots.map(s => `/api/romm/screenshot/${s.id}`),
local: true,
missing: !exists,
platform_display_name: localGame.platform.name,
platform_display_name: localGame.platform?.name,
summary: localGame.summary,
source: localGame.source,
source_id: localGame.source_id,

View file

@ -22,7 +22,7 @@ export const games = sqliteTable('games', {
export const gamesRelations = relations(games, ({ many, one }) => ({
screenshots: many(screenshots),
platform: one(platforms, {
fields: [games.id],
fields: [games.platform_id],
references: [platforms.id]
})
}));

View file

@ -34,6 +34,12 @@ export const system = new Elysia({ prefix: '/api/system' })
})
.get('/info', async () =>
{
let source = 'unknown';
if (process.env.APPIMAGE === 'true')
source = "AppImage";
if (process.env.FLATPAK === 'true')
source = "Flatpak";
return {
homeDir: os.homedir(),
user: os.userInfo().username,
@ -42,6 +48,7 @@ export const system = new Elysia({ prefix: '/api/system' })
hostname: os.hostname(),
steamDeck: process.env.SteamDeck,
machine: os.machine(),
source
};
})
.get('/notifications', ({ set }) =>