mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-18 02:31:19 +10:00
feat: very basic screenshot api
This commit is contained in:
18
server/api/v1/screenshots/game/[id]/index.get.ts
Normal file
18
server/api/v1/screenshots/game/[id]/index.get.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// get all user screenshots by game
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import screenshotManager from "~/server/internal/screenshots";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await aclManager.getUserIdACL(h3, ["screenshots:read"]);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const gameId = getRouterParam(h3, "id");
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing game ID",
|
||||
});
|
||||
|
||||
const results = await screenshotManager.getUserAllByGame(userId, gameId);
|
||||
return results;
|
||||
});
|
||||
27
server/api/v1/screenshots/game/[id]/index.post.ts
Normal file
27
server/api/v1/screenshots/game/[id]/index.post.ts
Normal file
@ -0,0 +1,27 @@
|
||||
// create new screenshot
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import screenshotManager from "~/server/internal/screenshots";
|
||||
|
||||
// TODO: make defineClientEventHandler instead?
|
||||
// only clients will be upload screenshots yea??
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await aclManager.getUserIdACL(h3, ["screenshots:new"]);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const gameId = getRouterParam(h3, "id");
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing game ID",
|
||||
});
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!game)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
|
||||
await screenshotManager.upload(userId, gameId, h3.node.req);
|
||||
});
|
||||
Reference in New Issue
Block a user