mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-20 11:41:14 +10:00
30 lines
827 B
TypeScript
30 lines
827 B
TypeScript
import { type } from "arktype";
|
|
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
|
import aclManager from "~/server/internal/acls";
|
|
import userLibraryManager from "~/server/internal/userlibrary";
|
|
|
|
const AddGame = type({
|
|
id: "string",
|
|
}).configure(throwingArktype);
|
|
|
|
/**
|
|
* Add game to user library
|
|
*/
|
|
export default defineEventHandler<{ body: typeof AddGame.infer }>(
|
|
async (h3) => {
|
|
const userId = await aclManager.getUserIdACL(h3, ["library:add"]);
|
|
if (!userId)
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Requires authentication",
|
|
});
|
|
|
|
const body = await readDropValidatedBody(h3, AddGame);
|
|
const gameId = body.id;
|
|
|
|
// Add the game to the default collection
|
|
await userLibraryManager.libraryAdd(gameId, userId);
|
|
return {};
|
|
},
|
|
);
|