feat(metadata): 'manual' metadata provider

This commit is contained in:
DecDuck
2024-12-26 19:54:49 +11:00
parent dad7ff67c3
commit 0b106fc497
11 changed files with 344 additions and 403 deletions
+17 -1
View File
@@ -72,10 +72,25 @@ export class MetadataHandler {
.filter((result) => result.status === "fulfilled")
.map((result) => result.value)
.flat();
return successfulResults;
}
async createGameWithoutMetadata(libraryBasePath: string) {
return await this.createGame(
{
id: "",
name: libraryBasePath,
icon: "",
description: "",
year: 0,
sourceId: "manual",
sourceName: "Manual",
},
libraryBasePath
);
}
async createGame(
result: InternalGameMetadataResult,
libraryBasePath: string
@@ -103,6 +118,7 @@ export class MetadataHandler {
try {
metadata = await provider.fetchGame({
id: result.id,
name: result.name,
// wrap in anonymous functions to keep references to this
publisher: (name: string) => this.fetchPublisher(name),
developer: (name: string) => this.fetchDeveloper(name),
+63
View File
@@ -0,0 +1,63 @@
import { MetadataSource } from "@prisma/client";
import { MetadataProvider } from ".";
import {
GameMetadataSearchResult,
_FetchGameMetadataParams,
GameMetadata,
_FetchPublisherMetadataParams,
PublisherMetadata,
_FetchDeveloperMetadataParams,
DeveloperMetadata,
} from "./types";
import * as jdenticon from "jdenticon";
export class ManualMetadataProvider implements MetadataProvider {
id() {
return "manual";
}
name() {
return "Manual";
}
source() {
return MetadataSource.Manual;
}
async search(query: string) {
return [];
}
async fetchGame({
name,
publisher,
developer,
createObject,
}: _FetchGameMetadataParams): Promise<GameMetadata> {
const icon = jdenticon.toPng(name, 512);
const iconId = createObject(icon);
return {
id: "manual",
name,
shortDescription: "Default description.",
description: "# Default description.",
released: new Date(),
publishers: [],
developers: [],
reviewCount: 0,
reviewRating: 0,
icon: iconId,
coverId: iconId,
bannerId: iconId,
images: [iconId],
};
}
async fetchPublisher(
params: _FetchPublisherMetadataParams
): Promise<PublisherMetadata> {
throw new Error("Method not implemented.");
}
async fetchDeveloper(
params: _FetchDeveloperMetadataParams
): Promise<DeveloperMetadata> {
throw new Error("Method not implemented.");
}
}