Add games library with IGDB, file explorer and static files script
This commit is contained in:
1 parent
a16444451a
commit
ec57bd73b3
65 files changed
+2230
-352
No files matched your search
@@ -0,0 +1,7 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { listFolder } from '#lib/server/files';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
return json(await listFolder(url.searchParams.get('path') ?? ''), { headers: { 'Cache-Control': 'no-cache' } });
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import { requireApiKey } from '#lib/server/library/auth';
|
||||
import { libraryDatabase } from '#lib/server/library/database';
|
||||
import { readBody } from '#lib/server/library/input';
|
||||
import { deleteGame, isIgdbId, saveGame } from '#lib/server/library/games';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
function checkedId(igdbId: string): string {
|
||||
if (!isIgdbId(igdbId)) error(400, `${igdbId} is not an IGDB ID`);
|
||||
return igdbId;
|
||||
}
|
||||
|
||||
export const PUT: RequestHandler = async ({ params, request }) => {
|
||||
requireApiKey(request);
|
||||
const igdbId = checkedId(params.igdbId);
|
||||
return json(await saveGame(await libraryDatabase(), igdbId, await readBody(request)));
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async ({ params, request }) => {
|
||||
requireApiKey(request);
|
||||
const igdbId = checkedId(params.igdbId);
|
||||
if (!deleteGame(await libraryDatabase(), igdbId)) error(404, `${igdbId} is not listed`);
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
Reference in new issue
Block a user