completed game importing; partial work on version importing

This commit is contained in:
DecDuck
2024-10-11 00:37:08 +11:00
parent 718f5ba514
commit a7c33e7d43
42 changed files with 1499 additions and 281 deletions

View 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 };
});

View 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;
});

View 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);
});

View 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;
});

View 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;
});

View 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 };
});

View 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 };
});

View File

@ -24,7 +24,9 @@ export default defineEventHandler(async (h3) => {
const userId = uuidv4();
const profilePictureObject = await h3.context.objects.createFromSource(
const profilePictureId = uuidv4();
await h3.context.objects.createFromSource(
profilePictureId,
() =>
$fetch<Readable>("https://avatars.githubusercontent.com/u/64579723?v=4", {
responseType: "stream",
@ -32,18 +34,12 @@ export default defineEventHandler(async (h3) => {
{},
[`anonymous:read`, `${userId}:write`]
);
if (!profilePictureObject)
throw createError({
statusCode: 500,
statusMessage: "Unable to import profile picture",
});
const user = await prisma.user.create({
data: {
username,
displayName: "DecDuck",
email: "",
profilePicture: profilePictureObject,
profilePicture: profilePictureId,
admin: true,
},
});

View File

@ -1,17 +1,25 @@
import clientHandler from "~/server/internal/clients/handler";
import { parsePlatform } from "~/server/internal/utils/parseplatform";
export default defineEventHandler(async (h3) => {
const body = await readBody(h3);
const name = body.name;
const platform = body.platform;
const platformRaw = body.platform;
if (!name || !platform)
if (!name || !platformRaw)
throw createError({
statusCode: 400,
statusMessage: "Missing name or platform in body",
});
const platform = parsePlatform(platformRaw);
if (!platform)
throw createError({
statusCode: 400,
statusMessage: "Invalid or unsupported platform",
});
const clientId = await clientHandler.initiate({ name, platform });
return `/client/${clientId}/callback`;

View File

@ -0,0 +1,36 @@
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const userId = await h3.context.session.getUserId(h3);
if (!userId) throw createError({ statusCode: 403 });
const rawGames = await prisma.game.findMany({
select: {
id: true,
mName: true,
mShortDescription: true,
mBannerId: true,
mDevelopers: {
select: {
id: true,
mName: true,
},
},
mPublishers: {
select: {
id: true,
mName: true,
},
},
versions: {
select: {
platform: true,
},
},
},
});
const games = rawGames.map((e) => ({...e, platforms: e.versions.map((e) => e.platform).filter((e, _, r) => !r.includes(e))}))
return games;
});