mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import { type } from "arktype";
|
import { type } from "arktype";
|
||||||
import { readDropValidatedBody } from "~/server/arktype";
|
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||||
import aclManager from "~/server/internal/acls";
|
import aclManager from "~/server/internal/acls";
|
||||||
import prisma from "~/server/internal/db/database";
|
import prisma from "~/server/internal/db/database";
|
||||||
import libraryManager from "~/server/internal/library";
|
import libraryManager from "~/server/internal/library";
|
||||||
@ -17,7 +17,7 @@ const ImportVersion = type({
|
|||||||
onlySetup: "boolean = false",
|
onlySetup: "boolean = false",
|
||||||
delta: "boolean = false",
|
delta: "boolean = false",
|
||||||
umuId: "string = ''",
|
umuId: "string = ''",
|
||||||
});
|
}).configure(throwingArktype);
|
||||||
|
|
||||||
export default defineEventHandler(async (h3) => {
|
export default defineEventHandler(async (h3) => {
|
||||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:new"]);
|
const allowed = await aclManager.allowSystemACL(h3, ["import:version:new"]);
|
||||||
@ -62,7 +62,7 @@ export default defineEventHandler(async (h3) => {
|
|||||||
if (!delta && !launch)
|
if (!delta && !launch)
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
statusMessage: "Startup executable is required for non-update versions",
|
statusMessage: "Launch executable is required for non-update versions",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,20 @@ export async function readDropValidatedBody<T>(
|
|||||||
event: H3Event,
|
event: H3Event,
|
||||||
validate: (data: object) => T,
|
validate: (data: object) => T,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const _body = await readBody(event);
|
const body = await readBody(event);
|
||||||
try {
|
try {
|
||||||
return validate(_body);
|
// Delete all values that are 'null'
|
||||||
|
if (typeof body === "object" && !Array.isArray(body) && body !== null) {
|
||||||
|
for (const [key, value] of Object.entries(body) as Array<
|
||||||
|
[string, unknown]
|
||||||
|
>) {
|
||||||
|
if (value === null) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
|
delete body[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validate(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const t = await useTranslation(event);
|
const t = await useTranslation(event);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user