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
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { ClientCapabilities } from "~~/prisma/client/enums";
|
|
import { defineClientEventHandler } from "~~/server/internal/clients/event-handler";
|
|
import { applicationSettings } from "~~/server/internal/config/application-configuration";
|
|
import prisma from "~~/server/internal/db/database";
|
|
|
|
export default defineClientEventHandler(
|
|
async (h3, { fetchClient, fetchUser }) => {
|
|
const client = await fetchClient();
|
|
if (!client.capabilities.includes(ClientCapabilities.CloudSaves))
|
|
throw createError({
|
|
statusCode: 403,
|
|
message: "Capability not allowed.",
|
|
});
|
|
const user = await fetchUser();
|
|
const gameId = getRouterParam(h3, "gameid");
|
|
if (!gameId)
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: "No gameID in route params",
|
|
});
|
|
|
|
const game = await prisma.game.findUnique({
|
|
where: { id: gameId },
|
|
select: { id: true },
|
|
});
|
|
if (!game)
|
|
throw createError({ statusCode: 400, message: "Invalid game ID" });
|
|
|
|
const saves = await prisma.saveSlot.findMany({
|
|
where: {
|
|
userId: user.id,
|
|
gameId: gameId,
|
|
},
|
|
orderBy: {
|
|
index: "asc",
|
|
},
|
|
});
|
|
|
|
const limit = await applicationSettings.get("saveSlotCountLimit");
|
|
if (saves.length + 1 > limit)
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: "Out of save slots",
|
|
});
|
|
|
|
let firstIndex = 0;
|
|
for (const save of saves) {
|
|
if (firstIndex == save.index) firstIndex++;
|
|
}
|
|
|
|
const newSlot = await prisma.saveSlot.create({
|
|
data: {
|
|
userId: user.id,
|
|
gameId: gameId,
|
|
index: firstIndex,
|
|
lastUsedClientId: client.id,
|
|
},
|
|
});
|
|
|
|
return newSlot;
|
|
},
|
|
);
|