mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 08:12:40 +10:00
completed game importing; partial work on version importing
This commit is contained in:
9
server/api/v1/admin/import/game/index.get.ts
Normal file
9
server/api/v1/admin/import/game/index.get.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const unimportedGames = await libraryManager.fetchAllUnimportedGames();
|
||||
return { unimportedGames };
|
||||
});
|
||||
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;
|
||||
});
|
||||
13
server/api/v1/admin/import/game/search.get.ts
Normal file
13
server/api/v1/admin/import/game/search.get.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = getQuery(h3);
|
||||
const search = query.q?.toString();
|
||||
if (!search)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid search" });
|
||||
|
||||
return await h3.context.metadataHandler.search(search);
|
||||
});
|
||||
22
server/api/v1/admin/import/version/index.get.ts
Normal file
22
server/api/v1/admin/import/version/index.get.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = await getQuery(h3);
|
||||
const gameId = query.id?.toString();
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id in request params",
|
||||
});
|
||||
|
||||
const unimportedVersions = await libraryManager.fetchUnimportedVersions(
|
||||
gameId
|
||||
);
|
||||
if (!unimportedVersions)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
|
||||
return unimportedVersions;
|
||||
});
|
||||
27
server/api/v1/admin/import/version/preload.get.ts
Normal file
27
server/api/v1/admin/import/version/preload.get.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = await getQuery(h3);
|
||||
const gameId = query.id?.toString();
|
||||
const versionName = query.version?.toString();
|
||||
if (!gameId || !versionName)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id or version in request params",
|
||||
});
|
||||
|
||||
const preload = await libraryManager.fetchUnimportedVersionInformation(
|
||||
gameId,
|
||||
versionName
|
||||
);
|
||||
if (!preload)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid game or version id/name",
|
||||
});
|
||||
|
||||
return preload;
|
||||
});
|
||||
6
server/api/v1/admin/index.get.ts
Normal file
6
server/api/v1/admin/index.get.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getUser(h3);
|
||||
if (!user)
|
||||
throw createError({ statusCode: 403, statusMessage: "Not authenticated" });
|
||||
return { admin: user.admin };
|
||||
});
|
||||
13
server/api/v1/admin/library/index.get.ts
Normal file
13
server/api/v1/admin/library/index.get.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const user = await h3.context.session.getAdminUser(h3);
|
||||
if (!user) throw createError({ statusCode: 403 });
|
||||
|
||||
const unimportedGames = await libraryManager.fetchAllUnimportedGames();
|
||||
const games = await libraryManager.fetchGamesWithStatus();
|
||||
|
||||
// Fetch other library data here
|
||||
|
||||
return { unimportedGames, games };
|
||||
});
|
||||
Reference in New Issue
Block a user