Admin home page #128 (#259)

* First iteration on the new PieChart component

* #128 Adds new admin home page

* Fixes code after merging conflicts

* Removes empty file

* Uses real data for admin home page, and improves style

* Reverts debugging code

* Defines missing variable

* Caches user stats data for admin home page

* Typo

* Styles improvements

* Invalidates cache on signup/signin

* Implements top 5 biggest games

* Improves styling

* Improves style

* Using generateManifest to get the proper size

* Reading data from cache

* Removes unnecessary import

* Improves caching mechanism for game sizes

* Removes lint errors

* Replaces piechart tooltip with colors in legend

* Fixes caching

* Fixes caching and slight improvement on pie chart colours

* Fixes a few bugs related to caching

* Fixes bug where app signin didn't refresh cache

* feat: style improvements

* fix: lint

---------

Co-authored-by: DecDuck <declanahofmeyr@gmail.com>
This commit is contained in:
Paco
2025-11-07 22:14:45 +00:00
committed by GitHub
parent 289034d0c8
commit dfa30c8a65
40 changed files with 1352 additions and 150 deletions

View File

@ -1,5 +1,5 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:delete"]);
@ -7,11 +7,7 @@ export default defineEventHandler(async (h3) => {
const gameId = getRouterParam(h3, "id")!;
await prisma.game.delete({
where: {
id: gameId,
},
});
libraryManager.deleteGame(gameId);
return {};
});

View File

@ -1,3 +1,4 @@
import type { GameVersion } from "~/prisma/client/client";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
@ -28,10 +29,22 @@ export default defineEventHandler(async (h3) => {
if (!game || !game.libraryId)
throw createError({ statusCode: 404, statusMessage: "Game ID not found" });
const getGameVersionSize = async (version: GameVersion) => {
const size = await libraryManager.getGameVersionSize(
gameId,
version.versionName,
);
return { ...version, size };
};
const gameWithVersionSize = {
...game,
versions: await Promise.all(game.versions.map(getGameVersionSize)),
};
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
game.libraryId,
game.libraryPath,
);
return { game, unimportedVersions };
return { game: gameWithVersionSize, unimportedVersions };
});

View File

@ -1,7 +1,7 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
const DeleteVersion = type({
id: "string",
@ -20,15 +20,7 @@ export default defineEventHandler<{ body: typeof DeleteVersion }>(
const gameId = body.id.toString();
const version = body.versionName.toString();
await prisma.gameVersion.delete({
where: {
gameId_versionName: {
gameId: gameId,
versionName: version,
},
},
});
await libraryManager.deleteGameVersion(gameId, version);
return {};
},
);

View File

@ -0,0 +1,27 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import { systemConfig } from "~/server/internal/config/sys-conf";
import libraryManager from "~/server/internal/library";
import userStatsManager from "~/server/internal/userstats";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const sources = await libraryManager.fetchLibraries();
const userStats = await userStatsManager.getUserStats();
const biggestGamesCombined =
await libraryManager.getBiggestGamesCombinedVersions(5);
const biggestGamesLatest =
await libraryManager.getBiggestGamesLatestVersions(5);
return {
gameCount: await prisma.game.count(),
version: systemConfig.getDropVersion(),
userStats,
sources,
biggestGamesLatest,
biggestGamesCombined,
};
});

View File

@ -2,7 +2,10 @@ import type { LibraryModel } from "~/prisma/client/models";
import aclManager from "~/server/internal/acls";
import libraryManager from "~/server/internal/library";
export type WorkingLibrarySource = LibraryModel & { working: boolean };
export type WorkingLibrarySource = LibraryModel & {
working: boolean;
fsStats?: { freeSpace: number; totalSpace: number } | undefined;
};
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [

View File

@ -3,8 +3,8 @@ import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
import type { WorkingLibrarySource } from "~/server/api/v1/admin/library/sources/index.get";
import { libraryConstructors } from "~/server/plugins/05.library-init";
import type { WorkingLibrarySource } from "./index.get";
const UpdateLibrarySource = type({
id: "string",
@ -49,8 +49,8 @@ export default defineEventHandler<{ body: typeof UpdateLibrarySource.infer }>(
},
});
await libraryManager.removeLibrary(source.id);
await libraryManager.addLibrary(newLibrary);
libraryManager.removeLibrary(source.id);
libraryManager.addLibrary(newLibrary);
const workingSource: WorkingLibrarySource = {
...updatedSource,

View File

@ -6,7 +6,7 @@ import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
import { libraryConstructors } from "~/server/plugins/05.library-init";
import type { WorkingLibrarySource } from "./index.get";
import type { WorkingLibrarySource } from "~/server/api/v1/admin/library/sources/index.get";
const CreateLibrarySource = type({
name: "string",
@ -52,11 +52,12 @@ export default defineEventHandler<{ body: typeof CreateLibrarySource.infer }>(
},
});
await libraryManager.addLibrary(library);
libraryManager.addLibrary(library);
const workingSource: WorkingLibrarySource = {
...source,
working: true,
fsStats: library.fsStats(),
};
return workingSource;

View File

@ -1,6 +1,7 @@
import { defineEventHandler, createError } from "h3";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import userStatsManager from "~/server/internal/userstats";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["user:delete"]);
@ -27,5 +28,6 @@ export default defineEventHandler(async (h3) => {
throw createError({ statusCode: 404, statusMessage: "User not found." });
await prisma.user.delete({ where: { id: userId } });
await userStatsManager.deleteUser();
return { success: true };
});

View File

@ -6,6 +6,7 @@ import objectHandler from "~/server/internal/objects";
import { type } from "arktype";
import { randomUUID } from "node:crypto";
import { throwingArktype } from "~/server/arktype";
import userStatsManager from "~/server/internal/userstats";
export const SharedRegisterValidator = type({
username: "string >= 5",
@ -86,5 +87,6 @@ export default defineEventHandler<{
prisma.invitation.delete({ where: { id: user.invitation } }),
]);
await userStatsManager.addUser();
return linkMec.user;
});

View File

@ -1,5 +1,6 @@
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
export default defineClientEventHandler(async (h3) => {
const query = getQuery(h3);
@ -26,5 +27,8 @@ export default defineClientEventHandler(async (h3) => {
statusMessage: "Game version not found",
});
return gameVersion;
return {
...gameVersion,
size: libraryManager.getGameVersionSize(id, version),
};
});

View File

@ -1,5 +1,6 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
export default defineEventHandler(async (h3) => {
const userId = await aclManager.getUserIdACL(h3, ["store:read"]);
@ -51,5 +52,7 @@ export default defineEventHandler(async (h3) => {
},
});
return { game, rating };
const size = await libraryManager.getGameVersionSize(game.id);
return { game, rating, size };
});