mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
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:
@@ -70,6 +70,11 @@ export const systemACLDescriptions: ObjectFromList<typeof systemACLs> = {
|
||||
"game:image:new": "Upload an image for a game.",
|
||||
"game:image:delete": "Delete an image for a game.",
|
||||
|
||||
"company:read": "Fetch companies.",
|
||||
"company:create": "Create a new company.",
|
||||
"company:update": "Update existing companies.",
|
||||
"company:delete": "Delete companies.",
|
||||
|
||||
"import:version:read":
|
||||
"Fetch versions to be imported, and information about versions to be imported.",
|
||||
"import:version:new": "Import a game version.",
|
||||
@@ -77,6 +82,10 @@ export const systemACLDescriptions: ObjectFromList<typeof systemACLs> = {
|
||||
"Fetch games to be imported, and search the metadata for games.",
|
||||
"import:game:new": "Import a game.",
|
||||
|
||||
"tags:read": "Fetch all tags",
|
||||
"tags:create": "Create a tag",
|
||||
"tags:delete": "Delete a tag",
|
||||
|
||||
"user:read": "Fetch any user's information.",
|
||||
"user:delete": "Delete a user.",
|
||||
|
||||
|
||||
@@ -65,6 +65,11 @@ export const systemACLs = [
|
||||
"game:image:new",
|
||||
"game:image:delete",
|
||||
|
||||
"company:read",
|
||||
"company:update",
|
||||
"company:create",
|
||||
"company:delete",
|
||||
|
||||
"import:version:read",
|
||||
"import:version:new",
|
||||
|
||||
@@ -78,6 +83,10 @@ export const systemACLs = [
|
||||
"news:create",
|
||||
"news:delete",
|
||||
|
||||
"tags:read",
|
||||
"tags:create",
|
||||
"tags:delete",
|
||||
|
||||
"task:read",
|
||||
"task:start",
|
||||
|
||||
|
||||
@@ -11,11 +11,15 @@ import { fuzzy } from "fast-fuzzy";
|
||||
import taskHandler from "../tasks";
|
||||
import { parsePlatform } from "../utils/parseplatform";
|
||||
import notificationSystem from "../notifications";
|
||||
import type { LibraryProvider } from "./provider";
|
||||
import { GameNotFoundError, type LibraryProvider } from "./provider";
|
||||
import { logger } from "../logging";
|
||||
|
||||
class LibraryManager {
|
||||
private libraries: Map<string, LibraryProvider<unknown>> = new Map();
|
||||
|
||||
private gameImportLocks: Map<string, Array<string>> = new Map(); // Library ID to Library Path
|
||||
private versionImportLocks: Map<string, Array<string>> = new Map(); // Game ID to Version Name
|
||||
|
||||
addLibrary(library: LibraryProvider<unknown>) {
|
||||
this.libraries.set(library.id(), library);
|
||||
}
|
||||
@@ -33,7 +37,7 @@ class LibraryManager {
|
||||
return libraryWithMetadata;
|
||||
}
|
||||
|
||||
async fetchAllUnimportedGames() {
|
||||
async fetchUnimportedGames() {
|
||||
const unimportedGames: { [key: string]: string[] } = {};
|
||||
|
||||
for (const [id, library] of this.libraries.entries()) {
|
||||
@@ -48,7 +52,9 @@ class LibraryManager {
|
||||
},
|
||||
});
|
||||
const providerUnimportedGames = games.filter(
|
||||
(e) => validGames.findIndex((v) => v.libraryPath == e) == -1,
|
||||
(e) =>
|
||||
validGames.findIndex((v) => v.libraryPath == e) == -1 &&
|
||||
!(this.gameImportLocks.get(id) ?? []).includes(e),
|
||||
);
|
||||
unimportedGames[id] = providerUnimportedGames;
|
||||
}
|
||||
@@ -67,30 +73,34 @@ class LibraryManager {
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
versions: true,
|
||||
},
|
||||
});
|
||||
if (!game) return undefined;
|
||||
|
||||
const versions = await provider.listVersions(libraryPath);
|
||||
const unimportedVersions = versions.filter(
|
||||
(e) => game.versions.findIndex((v) => v.versionName == e) == -1,
|
||||
);
|
||||
|
||||
return unimportedVersions;
|
||||
try {
|
||||
const versions = await provider.listVersions(libraryPath);
|
||||
const unimportedVersions = versions.filter(
|
||||
(e) =>
|
||||
game.versions.findIndex((v) => v.versionName == e) == -1 &&
|
||||
!(this.versionImportLocks.get(game.id) ?? []).includes(e),
|
||||
);
|
||||
return unimportedVersions;
|
||||
} catch (e) {
|
||||
if (e instanceof GameNotFoundError) {
|
||||
logger.warn(e);
|
||||
return undefined;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async fetchGamesWithStatus() {
|
||||
const games = await prisma.game.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
include: {
|
||||
versions: true,
|
||||
mName: true,
|
||||
mShortDescription: true,
|
||||
metadataSource: true,
|
||||
mIconObjectId: true,
|
||||
libraryId: true,
|
||||
libraryPath: true,
|
||||
library: true,
|
||||
},
|
||||
orderBy: {
|
||||
mName: "asc",
|
||||
@@ -98,19 +108,30 @@ class LibraryManager {
|
||||
});
|
||||
|
||||
return await Promise.all(
|
||||
games.map(async (e) => ({
|
||||
game: e,
|
||||
status: {
|
||||
noVersions: e.versions.length == 0,
|
||||
unimportedVersions: (await this.fetchUnimportedGameVersions(
|
||||
e.libraryId ?? "",
|
||||
e.libraryPath,
|
||||
))!,
|
||||
},
|
||||
})),
|
||||
games.map(async (e) => {
|
||||
const versions = await this.fetchUnimportedGameVersions(
|
||||
e.libraryId ?? "",
|
||||
e.libraryPath,
|
||||
);
|
||||
return {
|
||||
game: e,
|
||||
status: versions
|
||||
? {
|
||||
noVersions: e.versions.length == 0,
|
||||
unimportedVersions: versions,
|
||||
}
|
||||
: ("offline" as const),
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches recommendations and extra data about the version. Doesn't actually check if it's been imported.
|
||||
* @param gameId
|
||||
* @param versionName
|
||||
* @returns
|
||||
*/
|
||||
async fetchUnimportedVersionInformation(gameId: string, versionName: string) {
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
@@ -130,10 +151,7 @@ class LibraryManager {
|
||||
// No extension is common for Linux binaries
|
||||
"",
|
||||
],
|
||||
Windows: [
|
||||
// Pretty much the only one
|
||||
".exe",
|
||||
],
|
||||
Windows: [".exe", ".bat"],
|
||||
macOS: [
|
||||
// App files
|
||||
".app",
|
||||
@@ -188,6 +206,70 @@ class LibraryManager {
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Locks the game so you can't be imported
|
||||
* @param libraryId
|
||||
* @param libraryPath
|
||||
*/
|
||||
async lockGame(libraryId: string, libraryPath: string) {
|
||||
let games = this.gameImportLocks.get(libraryId);
|
||||
if (!games) this.gameImportLocks.set(libraryId, (games = []));
|
||||
|
||||
if (!games.includes(libraryPath)) games.push(libraryPath);
|
||||
|
||||
this.gameImportLocks.set(libraryId, games);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks the game, call once imported
|
||||
* @param libraryId
|
||||
* @param libraryPath
|
||||
*/
|
||||
async unlockGame(libraryId: string, libraryPath: string) {
|
||||
let games = this.gameImportLocks.get(libraryId);
|
||||
if (!games) this.gameImportLocks.set(libraryId, (games = []));
|
||||
|
||||
if (games.includes(libraryPath))
|
||||
games.splice(
|
||||
games.findIndex((e) => e === libraryPath),
|
||||
1,
|
||||
);
|
||||
|
||||
this.gameImportLocks.set(libraryId, games);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks a version so it can't be imported
|
||||
* @param gameId
|
||||
* @param versionName
|
||||
*/
|
||||
async lockVersion(gameId: string, versionName: string) {
|
||||
let versions = this.versionImportLocks.get(gameId);
|
||||
if (!versions) this.versionImportLocks.set(gameId, (versions = []));
|
||||
|
||||
if (!versions.includes(versionName)) versions.push(versionName);
|
||||
|
||||
this.versionImportLocks.set(gameId, versions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks the version, call once imported
|
||||
* @param libraryId
|
||||
* @param libraryPath
|
||||
*/
|
||||
async unlockVersion(gameId: string, versionName: string) {
|
||||
let versions = this.versionImportLocks.get(gameId);
|
||||
if (!versions) this.versionImportLocks.set(gameId, (versions = []));
|
||||
|
||||
if (versions.includes(gameId))
|
||||
versions.splice(
|
||||
versions.findIndex((e) => e === versionName),
|
||||
1,
|
||||
);
|
||||
|
||||
this.versionImportLocks.set(gameId, versions);
|
||||
}
|
||||
|
||||
async importVersion(
|
||||
gameId: string,
|
||||
versionName: string,
|
||||
@@ -218,6 +300,8 @@ class LibraryManager {
|
||||
const library = this.libraries.get(game.libraryId);
|
||||
if (!library) return undefined;
|
||||
|
||||
await this.lockVersion(gameId, versionName);
|
||||
|
||||
taskHandler.create({
|
||||
id: taskId,
|
||||
taskGroup: "import:game",
|
||||
@@ -294,6 +378,9 @@ class LibraryManager {
|
||||
|
||||
progress(100);
|
||||
},
|
||||
async finally() {
|
||||
await libraryManager.unlockVersion(gameId, versionName);
|
||||
},
|
||||
});
|
||||
|
||||
return taskId;
|
||||
|
||||
@@ -65,6 +65,11 @@ interface GameResult {
|
||||
reviews?: Array<{
|
||||
api_detail_url: string;
|
||||
}>;
|
||||
|
||||
genres?: Array<{
|
||||
name: string;
|
||||
id: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
interface ReviewResult {
|
||||
@@ -189,7 +194,7 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
context?.logger.warn(`Failed to import publisher "${pub}"`);
|
||||
continue;
|
||||
}
|
||||
context?.logger.info(`Imported publisher "${pub}"`);
|
||||
context?.logger.info(`Imported publisher "${pub.name}"`);
|
||||
publishers.push(res);
|
||||
}
|
||||
}
|
||||
@@ -224,11 +229,7 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
|
||||
const releaseDate = gameData.original_release_date
|
||||
? DateTime.fromISO(gameData.original_release_date).toJSDate()
|
||||
: DateTime.fromISO(
|
||||
`${gameData.expected_release_year ?? new Date().getFullYear()}-${
|
||||
gameData.expected_release_month ?? 1
|
||||
}-${gameData.expected_release_day ?? 1}`,
|
||||
).toJSDate();
|
||||
: new Date();
|
||||
|
||||
context?.progress(85);
|
||||
|
||||
@@ -249,6 +250,8 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
const tags = (gameData.genres ?? []).map((e) => e.name);
|
||||
|
||||
const metadata: GameMetadata = {
|
||||
id: gameData.guid,
|
||||
name: gameData.name,
|
||||
@@ -256,7 +259,7 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
description: longDescription,
|
||||
released: releaseDate,
|
||||
|
||||
tags: [],
|
||||
tags,
|
||||
|
||||
reviews,
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ export class IGDBProvider implements MetadataProvider {
|
||||
mReviewHref: currentGame.url,
|
||||
};
|
||||
|
||||
const tags = await this.getGenres(currentGame.genres);
|
||||
const genres = await this.getGenres(currentGame.genres);
|
||||
|
||||
const deck = this.trimMessage(currentGame.summary, 280);
|
||||
|
||||
@@ -461,12 +461,13 @@ export class IGDBProvider implements MetadataProvider {
|
||||
description: currentGame.summary,
|
||||
released,
|
||||
|
||||
genres,
|
||||
reviews: [review],
|
||||
|
||||
publishers,
|
||||
developers,
|
||||
|
||||
tags,
|
||||
tags: [],
|
||||
|
||||
icon,
|
||||
bannerId: banner,
|
||||
|
||||
@@ -18,6 +18,8 @@ import taskHandler, { wrapTaskContext } from "../tasks";
|
||||
import { randomUUID } from "crypto";
|
||||
import { fuzzy } from "fast-fuzzy";
|
||||
import { logger } from "~/server/internal/logging";
|
||||
import libraryManager from "../library";
|
||||
import type { GameTagModel } from "~/prisma/client/models";
|
||||
|
||||
export class MissingMetadataProviderConfig extends Error {
|
||||
private providerName: string;
|
||||
@@ -124,19 +126,22 @@ export class MetadataHandler {
|
||||
);
|
||||
}
|
||||
|
||||
private parseTags(tags: string[]) {
|
||||
const results: Array<Prisma.TagCreateOrConnectWithoutGamesInput> = [];
|
||||
private async parseTags(tags: string[]) {
|
||||
const results: Array<GameTagModel> = [];
|
||||
|
||||
tags.forEach((t) =>
|
||||
results.push({
|
||||
where: {
|
||||
name: t,
|
||||
},
|
||||
create: {
|
||||
name: t,
|
||||
},
|
||||
}),
|
||||
);
|
||||
for (const tag of tags) {
|
||||
const rawResults: GameTagModel[] =
|
||||
await prisma.$queryRaw`SELECT * FROM "GameTag" WHERE SIMILARITY(name, ${tag}) > 0.45;`;
|
||||
let resultTag = rawResults.at(0);
|
||||
if (!resultTag) {
|
||||
resultTag = await prisma.gameTag.create({
|
||||
data: {
|
||||
name: tag,
|
||||
},
|
||||
});
|
||||
}
|
||||
results.push(resultTag);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -180,6 +185,8 @@ export class MetadataHandler {
|
||||
});
|
||||
if (existing) return undefined;
|
||||
|
||||
await libraryManager.lockGame(libraryId, libraryPath);
|
||||
|
||||
const gameId = randomUUID();
|
||||
|
||||
const taskId = `import:${gameId}`;
|
||||
@@ -262,7 +269,7 @@ export class MetadataHandler {
|
||||
connectOrCreate: metadataHandler.parseRatings(metadata.reviews),
|
||||
},
|
||||
tags: {
|
||||
connectOrCreate: metadataHandler.parseTags(metadata.tags),
|
||||
connect: await metadataHandler.parseTags(metadata.tags),
|
||||
},
|
||||
|
||||
libraryId,
|
||||
@@ -271,6 +278,10 @@ export class MetadataHandler {
|
||||
});
|
||||
|
||||
logger.info(`Finished game import.`);
|
||||
progress(100);
|
||||
},
|
||||
async finally() {
|
||||
await libraryManager.unlockGame(libraryId, libraryPath);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -206,6 +206,8 @@ class TaskHandler {
|
||||
};
|
||||
}
|
||||
|
||||
if (task.finally) await task.finally();
|
||||
|
||||
taskEntry.endTime = new Date().toISOString();
|
||||
await updateAllClients();
|
||||
|
||||
@@ -427,6 +429,7 @@ export interface Task {
|
||||
taskGroup: TaskGroup;
|
||||
name: string;
|
||||
run: (context: TaskRunContext) => Promise<void>;
|
||||
finally?: () => Promise<void> | void;
|
||||
acls: GlobalACL[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user