Store overhaul (#142)

* feat: small library tweaks + company page

* feat: new store view

* fix: ci merge error

* feat: add genres to store page

* feat: sorting

* feat: lock game/version imports while their tasks are running

* feat: feature games

* feat: tag based filtering

* fix: make tags alphabetical

* refactor: move a bunch of i18n to common

* feat: add localizations for everything

* fix: title description on panel

* fix: feature carousel text

* fix: i18n footer strings

* feat: add tag page

* fix: develop merge

* feat: offline games support (don't error out if provider throws)

* feat: tag management

* feat: show library next to game import + small fixes

* feat: most of the company and tag managers

* feat: company text field editing

* fix: small fixes + tsgo experiemental

* feat: upload icon and banner

* feat: store infinite scrolling and bulk import mode

* fix: lint

* fix: add drop-base to prettier ignore
This commit is contained in:
DecDuck
2025-07-30 13:40:49 +10:00
committed by GitHub
parent 1ae051f066
commit 8363de2eed
97 changed files with 3506 additions and 524 deletions

View File

@ -0,0 +1,51 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import objectHandler from "~/server/internal/objects";
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const companyId = getRouterParam(h3, "id")!;
const company = await prisma.company.findUnique({
where: {
id: companyId,
},
});
if (!company)
throw createError({ statusCode: 400, statusMessage: "Invalid company id" });
const result = await handleFileUpload(h3, {}, ["internal:read"], 1);
if (!result)
throw createError({
statusCode: 400,
statusMessage: "File upload required (multipart form)",
});
const [ids, , pull, dump] = result;
const id = ids.at(0);
if (!id)
throw createError({
statusCode: 400,
statusMessage: "Upload at least one file.",
});
try {
await objectHandler.deleteAsSystem(company.mBannerObjectId);
await prisma.company.update({
where: {
id: companyId,
},
data: {
mBannerObjectId: id,
},
});
await pull();
} catch {
await dump();
}
return { id: id };
});

View File

@ -0,0 +1,37 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const GameDelete = type({
id: "string",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const companyId = getRouterParam(h3, "id")!;
const body = await readDropValidatedBody(h3, GameDelete);
await prisma.game.update({
where: {
id: body.id,
},
data: {
publishers: {
disconnect: {
id: companyId,
},
},
developers: {
disconnect: {
id: companyId,
},
},
},
});
return;
});

View File

@ -0,0 +1,37 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const GamePatch = type({
action: "'developed' | 'published'",
enabled: "boolean",
id: "string",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const companyId = getRouterParam(h3, "id")!;
const body = await readDropValidatedBody(h3, GamePatch);
const action = body.action === "developed" ? "developers" : "publishers";
const actionType = body.enabled ? "connect" : "disconnect";
await prisma.game.update({
where: {
id: body.id,
},
data: {
[action]: {
[actionType]: {
id: companyId,
},
},
},
});
return;
});

View File

@ -0,0 +1,69 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const GamePost = type({
published: "boolean",
developed: "boolean",
id: "string",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const companyId = getRouterParam(h3, "id")!;
const body = await readDropValidatedBody(h3, GamePost);
if (!body.published && !body.developed)
throw createError({
statusCode: 400,
statusMessage: "Must be related (either developed or published).",
});
const publisherConnect = body.published
? {
publishers: {
connect: {
id: companyId,
},
},
}
: undefined;
const developerConnect = body.developed
? {
developers: {
connect: {
id: companyId,
},
},
}
: undefined;
const game = await prisma.game.update({
where: {
id: body.id,
},
data: {
...publisherConnect,
...developerConnect,
},
include: {
publishers: {
select: {
id: true,
},
},
developers: {
select: {
id: true,
},
},
},
});
return game;
});

View File

@ -0,0 +1,51 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import objectHandler from "~/server/internal/objects";
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const companyId = getRouterParam(h3, "id")!;
const company = await prisma.company.findUnique({
where: {
id: companyId,
},
});
if (!company)
throw createError({ statusCode: 400, statusMessage: "Invalid company id" });
const result = await handleFileUpload(h3, {}, ["internal:read"], 1);
if (!result)
throw createError({
statusCode: 400,
statusMessage: "File upload required (multipart form)",
});
const [ids, , pull, dump] = result;
const id = ids.at(0);
if (!id)
throw createError({
statusCode: 400,
statusMessage: "Upload at least one file.",
});
try {
await objectHandler.deleteAsSystem(company.mLogoObjectId);
await prisma.company.update({
where: {
id: companyId,
},
data: {
mLogoObjectId: id,
},
});
await pull();
} catch {
await dump();
}
return { id: id };
});

View File

@ -0,0 +1,14 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:delete"]);
if (!allowed) throw createError({ statusCode: 403 });
const id = getRouterParam(h3, "id")!;
const company = await prisma.company.deleteMany({ where: { id } });
if (company.count == 0)
throw createError({ statusCode: 404, statusMessage: "Company not found" });
return;
});

View File

@ -0,0 +1,54 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const id = getRouterParam(h3, "id")!;
const company = await prisma.company.findUnique({
where: { id },
include: {
published: {
select: {
id: true,
},
},
developed: {
select: {
id: true,
},
},
},
});
if (!company)
throw createError({ statusCode: 404, statusMessage: "Company not found" });
const games = await prisma.game.findMany({
where: {
OR: [
{
developers: {
some: {
id: company.id,
},
},
},
{
publishers: {
some: {
id: company.id,
},
},
},
],
},
distinct: ["id"],
});
const companyFlatten = {
...company,
developed: company.developed.map((e) => e.id),
published: company.published.map((e) => e.id),
};
return { company: companyFlatten, games };
});

View File

@ -0,0 +1,23 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readBody(h3);
const id = getRouterParam(h3, "id")!;
const restOfTheBody = { ...body };
delete restOfTheBody["id"];
const newObj = await prisma.company.update({
where: {
id: id,
},
data: restOfTheBody,
// I would put a select here, but it would be based on the body, and muck up the types
});
return newObj;
});

View File

@ -0,0 +1,10 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["company:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const companies = await prisma.company.findMany({});
return companies;
});

View File

@ -1,17 +1,11 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler<{ query: { id: string } }>(async (h3) => {
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:delete"]);
if (!allowed) throw createError({ statusCode: 403 });
const query = getQuery(h3);
const gameId = query.id?.toString();
if (!gameId)
throw createError({
statusCode: 400,
statusMessage: "Missing id in query",
});
const gameId = getRouterParam(h3, "id")!;
await prisma.game.delete({
where: {

View File

@ -0,0 +1,40 @@
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:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const gameId = getRouterParam(h3, "id")!;
const game = await prisma.game.findUnique({
where: {
id: gameId,
},
include: {
versions: {
orderBy: {
versionIndex: "asc",
},
select: {
versionIndex: true,
versionName: true,
platform: true,
delta: true,
},
},
tags: true,
},
});
if (!game || !game.libraryId)
throw createError({ statusCode: 404, statusMessage: "Game ID not found" });
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
game.libraryId,
game.libraryPath,
);
return { game, unimportedVersions };
});

View File

@ -6,9 +6,7 @@ export default defineEventHandler(async (h3) => {
if (!allowed) throw createError({ statusCode: 403 });
const body = await readBody(h3);
const id = body.id;
if (!id)
throw createError({ statusCode: 400, statusMessage: "Missing id in body" });
const id = getRouterParam(h3, "id")!;
const restOfTheBody = { ...body };
delete restOfTheBody["id"];

View File

@ -14,6 +14,8 @@ export default defineEventHandler(async (h3) => {
statusMessage: "This endpoint requires multipart form data.",
});
const gameId = getRouterParam(h3, "id")!;
const uploadResult = await handleFileUpload(h3, {}, ["internal:read"], 1);
if (!uploadResult)
throw createError({
@ -28,7 +30,6 @@ export default defineEventHandler(async (h3) => {
// handleFileUpload reads the rest of the options for us.
const name = options.name;
const description = options.description;
const gameId = options.id;
const updateModel: Prisma.GameUpdateInput = {
mName: name,

View File

@ -0,0 +1,29 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const PatchTags = type({
tags: "string[]",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readDropValidatedBody(h3, PatchTags);
const id = getRouterParam(h3, "id")!;
await prisma.game.update({
where: {
id,
},
data: {
tags: {
connect: body.tags.map((e) => ({ id: e })),
},
},
});
return;
});

View File

@ -1,45 +1,16 @@
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:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const query = getQuery(h3);
const gameId = query.id?.toString();
if (!gameId)
throw createError({
statusCode: 400,
statusMessage: "Missing id in query",
});
const game = await prisma.game.findUnique({
where: {
id: gameId,
},
include: {
versions: {
orderBy: {
versionIndex: "asc",
},
select: {
versionIndex: true,
versionName: true,
platform: true,
delta: true,
},
},
return await prisma.game.findMany({
select: {
id: true,
mName: true,
mShortDescription: true,
mIconObjectId: true,
},
});
if (!game || !game.libraryId)
throw createError({ statusCode: 404, statusMessage: "Game ID not found" });
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
game.libraryId,
game.libraryPath,
);
return { game, unimportedVersions };
});

View File

@ -5,10 +5,13 @@ export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["import:game:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const unimportedGames = await libraryManager.fetchAllUnimportedGames();
const unimportedGames = await libraryManager.fetchUnimportedGames();
const libraries = Object.fromEntries(
(await libraryManager.fetchLibraries()).map((e) => [e.id, e]),
);
const iterableUnimportedGames = Object.entries(unimportedGames)
.map(([libraryId, gameArray]) =>
gameArray.map((e) => ({ game: e, library: libraryId })),
gameArray.map((e) => ({ game: e, library: libraries[libraryId] })),
)
.flat();
return { unimportedGames: iterableUnimportedGames };

View File

@ -5,7 +5,7 @@ export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["library:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const unimportedGames = await libraryManager.fetchAllUnimportedGames();
const unimportedGames = await libraryManager.fetchUnimportedGames();
const games = await libraryManager.fetchGamesWithStatus();
// Fetch other library data here

View File

@ -1,13 +0,0 @@
import aclManager from "~/server/internal/acls";
import { applicationSettings } from "~/server/internal/config/application-configuration";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.getUserACL(h3, ["settings:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const showGamePanelTextDecoration = await applicationSettings.get(
"showGamePanelTextDecoration",
);
return { showGamePanelTextDecoration };
});

View File

@ -0,0 +1,14 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["tags:delete"]);
if (!allowed) throw createError({ statusCode: 403 });
const id = getRouterParam(h3, "id")!;
const tag = await prisma.gameTag.deleteMany({ where: { id } });
if (tag.count == 0)
throw createError({ statusCode: 404, statusMessage: "Tag not found" });
return;
});

View File

@ -0,0 +1,10 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["tags:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const tags = await prisma.gameTag.findMany({ orderBy: { name: "asc" } });
return tags;
});

View File

@ -0,0 +1,22 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const CreateTag = type({
name: "string",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["tags:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readDropValidatedBody(h3, CreateTag);
const tag = await prisma.gameTag.create({
data: {
...body,
},
});
return tag;
});