Add SQLite library with API, library desktop apps and MobyGames scraper
This commit is contained in:
1 parent
6674428346
commit
a16444451a
69 files changed
+2988
-1026
No files matched your search
@@ -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 { deleteMedia, isImdbId, saveMedia } from '#lib/server/library/media';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
function checkedId(imdbId: string): string {
|
||||
if (!isImdbId(imdbId)) error(400, `${imdbId} is not an IMDb ID`);
|
||||
return imdbId;
|
||||
}
|
||||
|
||||
export const PUT: RequestHandler = async ({ params, request }) => {
|
||||
requireApiKey(request);
|
||||
const imdbId = checkedId(params.imdbId);
|
||||
return json(await saveMedia(await libraryDatabase(), imdbId, await readBody(request)));
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async ({ params, request }) => {
|
||||
requireApiKey(request);
|
||||
const imdbId = checkedId(params.imdbId);
|
||||
if (!deleteMedia(await libraryDatabase(), imdbId)) error(404, `${imdbId} is not listed`);
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
Reference in new issue
Block a user