mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
completed game importing; partial work on version importing
This commit is contained in:
36
server/api/v1/admin/import/game/index.post.ts
Normal file
36
server/api/v1/admin/import/game/index.post.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
import {
|
||||
GameMetadataSearchResult,
|
||||
GameMetadataSource,
|
||||
} from "~/server/internal/metadata/types";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readBody(h3);
|
||||
|
||||
const path = body.path;
|
||||
const metadata = body.metadata as GameMetadataSearchResult &
|
||||
GameMetadataSource;
|
||||
if (!path)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Path missing from body",
|
||||
});
|
||||
if (!metadata.id || !metadata.sourceId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Metadata IDs missing from body",
|
||||
});
|
||||
|
||||
const validPath = await libraryManager.checkUnimportedGamePath(path);
|
||||
if (!validPath)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid unimported game path",
|
||||
});
|
||||
|
||||
const game = await h3.context.metadataHandler.createGame(metadata, path);
|
||||
return game;
|
||||
});
|
||||
Reference in New Issue
Block a user