mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-16 17:51:17 +10:00
* feat: database redist support * feat: rearchitecture of database schemas, migration reset, and #180 * feat: import redists * fix: giantbomb logging bug * feat: partial user platform support + statusMessage -> message * feat: add user platform filters to store view * fix: sanitize svg uploads ... copilot suggested this I feel dirty. * feat: beginnings of platform & redist management * feat: add server side redist patching * fix: update drop-base commit * feat: import of custom platforms & file extensions * fix: redelete platform * fix: remove platform * feat: uninstall commands, new R UI * checkpoint: before migrating to nuxt v4 * update to nuxt 4 * fix: fixes for Nuxt v4 update * fix: remaining type issues * feat: initial feedback to import other kinds of versions * working commit * fix: lint * feat: redist import
102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import type { IncomingMessage } from "node:http";
|
|
import objectHandler from "../objects";
|
|
import stream from "node:stream/promises";
|
|
import prisma from "../db/database";
|
|
|
|
class ScreenshotManager {
|
|
/**
|
|
* Gets a specific screenshot
|
|
* @param id
|
|
* @returns
|
|
*/
|
|
async get(id: string) {
|
|
return await prisma.screenshot.findUnique({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get all user screenshots
|
|
* @param userId
|
|
* @returns
|
|
*/
|
|
async getUserAll(userId: string) {
|
|
const results = await prisma.screenshot.findMany({
|
|
where: {
|
|
userId,
|
|
},
|
|
});
|
|
return results;
|
|
}
|
|
|
|
/**
|
|
* Get all user screenshots in a specific game
|
|
* @param userId
|
|
* @param gameId
|
|
* @returns
|
|
*/
|
|
async getUserAllByGame(userId: string, gameId: string) {
|
|
const results = await prisma.screenshot.findMany({
|
|
where: {
|
|
gameId,
|
|
userId,
|
|
},
|
|
});
|
|
return results;
|
|
}
|
|
|
|
/**
|
|
* Delete a specific screenshot
|
|
* @param id
|
|
*/
|
|
async delete(id: string) {
|
|
const deletedScreenshot = await prisma.screenshot.delete({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
await objectHandler.deleteAsSystem(deletedScreenshot.objectId);
|
|
}
|
|
|
|
/**
|
|
* Allows a user to upload a screenshot
|
|
* @param userId
|
|
* @param gameId
|
|
* @param inputStream
|
|
*/
|
|
async upload(userId: string, gameId: string, inputStream: IncomingMessage) {
|
|
const objectId = randomUUID();
|
|
const saveStream = await objectHandler.createWithStream(
|
|
objectId,
|
|
{
|
|
// TODO: set createAt to the time screenshot was taken
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
[`${userId}:read`], // This is a system tracked object, so we don't want users to have direct write access to it
|
|
);
|
|
if (!saveStream)
|
|
throw createError({
|
|
statusCode: 500,
|
|
message: "Failed to create writing stream to storage backend.",
|
|
});
|
|
|
|
// pipe into object store
|
|
await stream.pipeline(inputStream, saveStream);
|
|
|
|
await prisma.screenshot.create({
|
|
data: {
|
|
gameId,
|
|
userId,
|
|
objectId,
|
|
private: true,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export const screenshotManager = new ScreenshotManager();
|
|
export default screenshotManager;
|