mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 16:51:15 +10:00
feat: add cloudsave configuration w/ ludusavi search
This commit is contained in:
69
server/api/v1/admin/game/cloudsaves/index.patch.ts
Normal file
69
server/api/v1/admin/game/cloudsaves/index.patch.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { type } from "arktype";
|
||||
import { CloudSaveType } from "~/prisma/client";
|
||||
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
const UpdateEntry = type({
|
||||
id: "string",
|
||||
name: "string",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, [
|
||||
"game:cloudsaves:update",
|
||||
]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readDropValidatedBody(h3, UpdateEntry);
|
||||
const entry = await prisma.ludusaviEntry.findUnique({
|
||||
where: {
|
||||
name: body.name,
|
||||
},
|
||||
include: {
|
||||
entries: true,
|
||||
},
|
||||
});
|
||||
if (!entry)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid Ludusavi name",
|
||||
});
|
||||
|
||||
const configuration = await prisma.cloudSaveConfiguration.upsert({
|
||||
where: {
|
||||
gameId: body.id,
|
||||
},
|
||||
create: {
|
||||
gameId: body.id,
|
||||
type: CloudSaveType.Ludusavi,
|
||||
ludusaviEntryName: entry.name,
|
||||
},
|
||||
update: {
|
||||
type: CloudSaveType.Ludusavi,
|
||||
ludusaviEntryName: entry.name,
|
||||
},
|
||||
include: {
|
||||
ludusaviEntry: {
|
||||
include: {
|
||||
entries: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.game.update({
|
||||
where: {
|
||||
id: body.id,
|
||||
},
|
||||
data: {
|
||||
cloudSaveConfiguration: {
|
||||
connect: {
|
||||
gameId: body.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return configuration;
|
||||
});
|
||||
21
server/api/v1/admin/game/cloudsaves/search.get.ts
Normal file
21
server/api/v1/admin/game/cloudsaves/search.get.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
||||
/* eslint-disable @typescript-eslint/no-extra-non-null-assertion */
|
||||
|
||||
import type { LudusaviEntry } from "~/prisma/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:cloudsaves:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = getQuery(h3);
|
||||
const name = query.name?.toString()!!;
|
||||
|
||||
// Remove all non alphanumberical characters
|
||||
const sanatisedName = name.replaceAll(/[^a-zA-Z\d\s:]/g, "");
|
||||
|
||||
const results = await prisma.$queryRaw`SELECT * FROM "LudusaviEntry" ORDER BY SIMILARITY(name, ${sanatisedName}) DESC LIMIT 20;`;
|
||||
|
||||
return results as Array<LudusaviEntry>;
|
||||
});
|
||||
@ -30,6 +30,15 @@ export default defineEventHandler(async (h3) => {
|
||||
delta: true,
|
||||
},
|
||||
},
|
||||
cloudSaveConfiguration: {
|
||||
include: {
|
||||
ludusaviEntry: {
|
||||
include: {
|
||||
entries: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user