feat: very basic screenshot api

This commit is contained in:
Huskydog9988
2025-05-15 15:51:35 -04:00
parent a549d3a1db
commit b1613b6dc9
9 changed files with 126 additions and 5 deletions
@@ -22,6 +22,10 @@ export const userACLDescriptions: ObjectFromList<typeof userACLs> = {
"notifications:listen": "Connect to a websocket to recieve notifications.",
"notifications:delete": "Delete this account's notifications.",
"screenshots:new": "Create screenshots for this account",
"screenshots:read": "Read all screenshots for this account",
"screenshots:delete": "Delete a screenshot for this account",
"collections:new": "Create collections for this account.",
"collections:read": "Fetch all collections (including library).",
"collections:delete": "Delete a collection for this account.",
+10
View File
@@ -17,6 +17,10 @@ export const userACLs = [
"notifications:listen",
"notifications:delete",
"screenshots:new",
"screenshots:read",
"screenshots:delete",
"collections:new",
"collections:read",
"collections:delete",
@@ -83,6 +87,12 @@ class ACLManager {
return token;
}
/**
* Get userId and require one of the specified acls
* @param request
* @param acls
* @returns
*/
async getUserIdACL(request: MinimumRequestObject | undefined, acls: UserACL) {
if (!request)
throw new Error("Native web requests not available - weird deployment?");
+20 -4
View File
@@ -13,7 +13,16 @@ class ScreenshotManager {
});
}
async getAllByGame(gameId: string, userId: string) {
async getUserAll(userId: string) {
const results = await prisma.screenshot.findMany({
where: {
userId,
},
});
return results;
}
async getUserAllByGame(userId: string, gameId: string) {
const results = await prisma.screenshot.findMany({
where: {
gameId,
@@ -31,9 +40,16 @@ class ScreenshotManager {
});
}
async upload(gameId: string, userId: string, inputStream: IncomingMessage) {
async upload(userId: string, gameId: string, inputStream: IncomingMessage) {
const objectId = randomUUID();
const saveStream = await objectHandler.createWithStream(objectId, {}, []);
const saveStream = await objectHandler.createWithStream(
objectId,
{
// TODO: set createAt to the time screenshot was taken
createdAt: new Date().toISOString(),
},
[`${userId}:read`, `${userId}:delete`],
);
if (!saveStream)
throw createError({
statusCode: 500,
@@ -43,12 +59,12 @@ class ScreenshotManager {
// pipe into object store
await stream.pipeline(inputStream, saveStream);
// TODO: set createAt to the time screenshot was taken
await prisma.screenshot.create({
data: {
gameId,
userId,
objectId,
private: true,
},
});
}