mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 00:31:25 +10:00
* feat: start of library backends * feat: update backend routes and create initializer * feat: add legacy library creation * fix: resolve frontend type errors * fix: runtime errors * fix: lint
This commit is contained in:
@ -1,37 +1,46 @@
|
||||
import { type } from "arktype";
|
||||
import { throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
import metadataHandler from "~/server/internal/metadata";
|
||||
import type {
|
||||
GameMetadataSearchResult,
|
||||
GameMetadataSource,
|
||||
} from "~/server/internal/metadata/types";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:game:new"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
const ImportGameBody = type({
|
||||
library: "string",
|
||||
path: "string",
|
||||
["metadata?"]: {
|
||||
id: "string",
|
||||
sourceId: "string",
|
||||
name: "string",
|
||||
},
|
||||
}).configure(throwingArktype);
|
||||
|
||||
const body = await readBody(h3);
|
||||
export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
|
||||
async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:game:new"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const path = body.path;
|
||||
const metadata = body.metadata as GameMetadataSearchResult &
|
||||
GameMetadataSource;
|
||||
if (!path)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Path missing from body",
|
||||
});
|
||||
const { library, path, metadata } = await readValidatedBody(
|
||||
h3,
|
||||
ImportGameBody,
|
||||
);
|
||||
|
||||
const validPath = await libraryManager.checkUnimportedGamePath(path);
|
||||
if (!validPath)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid unimported game path",
|
||||
});
|
||||
if (!path)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Path missing from body",
|
||||
});
|
||||
|
||||
if (!metadata || !metadata.id || !metadata.sourceId) {
|
||||
console.log(metadata);
|
||||
return await metadataHandler.createGameWithoutMetadata(path);
|
||||
} else {
|
||||
return await metadataHandler.createGame(metadata, path);
|
||||
}
|
||||
});
|
||||
const valid = await libraryManager.checkUnimportedGamePath(library, path);
|
||||
if (!valid)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid library or game.",
|
||||
});
|
||||
|
||||
if (!metadata) {
|
||||
return await metadataHandler.createGameWithoutMetadata(library, path);
|
||||
} else {
|
||||
return await metadataHandler.createGame(metadata, library, path);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user