* ci: pull version from package.json on build

* fix: implicit any type

* feat: inital support for logger

* style: fix lint

* feat: move more logging over to pino

* fix: logging around company importing
This commit is contained in:
Husky
2025-07-08 22:01:23 -04:00
committed by GitHub
parent e4fbc7cd50
commit 2b70cea4e0
33 changed files with 481 additions and 171 deletions
+18 -10
View File
@@ -169,7 +169,7 @@ export class GiantBombProvider implements MetadataProvider {
{ id, publisher, developer, createObject }: _FetchGameMetadataParams,
context?: TaskRunContext,
): Promise<GameMetadata> {
context?.log("Using GiantBomb provider");
context?.logger.info("Using GiantBomb provider");
const result = await this.request<GameResult>("game", id, {});
const gameData = result.data.results;
@@ -181,10 +181,14 @@ export class GiantBombProvider implements MetadataProvider {
const publishers: Company[] = [];
if (gameData.publishers) {
for (const pub of gameData.publishers) {
context?.log(`Importing publisher "${pub.name}"`);
context?.logger.info(`Importing publisher "${pub.name}"`);
const res = await publisher(pub.name);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(`Failed to import publisher "${pub}"`);
continue;
}
context?.logger.info(`Imported publisher "${pub}"`);
publishers.push(res);
}
}
@@ -194,10 +198,14 @@ export class GiantBombProvider implements MetadataProvider {
const developers: Company[] = [];
if (gameData.developers) {
for (const dev of gameData.developers) {
context?.log(`Importing developer "${dev.name}"`);
context?.logger.info(`Importing developer "${dev.name}"`);
const res = await developer(dev.name);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(`Failed to import developer "${dev}"`);
continue;
}
context?.logger.info(`Imported developer "${dev}"`);
developers.push(res);
}
}
@@ -211,7 +219,7 @@ export class GiantBombProvider implements MetadataProvider {
const images = [banner, ...imageURLs.map(createObject)];
context?.log(`Found all images. Total of ${images.length + 1}.`);
context?.logger.info(`Found all images. Total of ${images.length + 1}.`);
const releaseDate = gameData.original_release_date
? DateTime.fromISO(gameData.original_release_date).toJSDate()
@@ -225,7 +233,7 @@ export class GiantBombProvider implements MetadataProvider {
const reviews: GameMetadataRating[] = [];
if (gameData.reviews) {
context?.log("Found reviews, importing...");
context?.logger.info("Found reviews, importing...");
for (const { api_detail_url } of gameData.reviews) {
const reviewId = api_detail_url.split("/").at(-2);
if (!reviewId) continue;
@@ -260,7 +268,7 @@ export class GiantBombProvider implements MetadataProvider {
images,
};
context?.log("GiantBomb provider finished.");
context?.logger.info("GiantBomb provider finished.");
context?.progress(100);
return metadata;
@@ -268,7 +276,7 @@ export class GiantBombProvider implements MetadataProvider {
async fetchCompany({
query,
createObject,
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata> {
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata | undefined> {
const results = await this.request<Array<CompanySearchResult>>(
"search",
"",
@@ -279,7 +287,7 @@ export class GiantBombProvider implements MetadataProvider {
const company =
results.data.results.find((e) => e.name == query) ??
results.data.results.at(0);
if (!company) throw new Error(`No results for "${query}"`);
if (!company) return undefined;
const longDescription = company.description
? this.turndown.turndown(company.description)
+24 -11
View File
@@ -14,6 +14,7 @@ import axios from "axios";
import { DateTime } from "luxon";
import * as jdenticon from "jdenticon";
import type { TaskRunContext } from "../tasks";
import { logger } from "~/server/internal/logging";
type IGDBID = number;
@@ -163,7 +164,7 @@ export class IGDBProvider implements MetadataProvider {
}
private async authWithTwitch() {
console.log("IGDB authorizing with twitch");
logger.info("IGDB authorizing with twitch");
const params = new URLSearchParams({
client_id: this.clientId,
client_secret: this.clientSecret,
@@ -186,7 +187,7 @@ export class IGDBProvider implements MetadataProvider {
seconds: response.data.expires_in,
});
console.log("IDGB done authorizing with twitch");
logger.info("IDGB done authorizing with twitch");
}
private async refreshCredentials() {
@@ -354,16 +355,16 @@ export class IGDBProvider implements MetadataProvider {
const currentGame = (await this.request<IGDBGameFull>("games", body)).at(0);
if (!currentGame) throw new Error("No game found on IGDB with that id");
context?.log("Using IDGB provider.");
context?.logger.info("Using IDGB provider.");
let iconRaw;
const cover = currentGame.cover;
if (cover !== undefined) {
context?.log("Found cover URL, using...");
context?.logger.info("Found cover URL, using...");
iconRaw = await this.getCoverURL(cover);
} else {
context?.log("Missing cover URL, using fallback...");
context?.logger.info("Missing cover URL, using fallback...");
iconRaw = jdenticon.toPng(id, 512);
}
@@ -400,7 +401,7 @@ export class IGDBProvider implements MetadataProvider {
>("companies", `where id = ${foundInvolved.company}; fields name;`);
for (const company of findCompanyResponse) {
context?.log(
context?.logger.info(
`Found involved company "${company.name}" as: ${foundInvolved.developer ? "developer, " : ""}${foundInvolved.publisher ? "publisher" : ""}`,
);
@@ -408,13 +409,25 @@ export class IGDBProvider implements MetadataProvider {
// CANNOT use else since a company can be both
if (foundInvolved.developer) {
const res = await developer(company.name);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(
`Failed to import developer "${company.name}"`,
);
continue;
}
context?.logger.info(`Imported developer "${company.name}"`);
developers.push(res);
}
if (foundInvolved.publisher) {
const res = await publisher(company.name);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(
`Failed to import publisher "${company.name}"`,
);
continue;
}
context?.logger.info(`Imported publisher "${company.name}"`);
publishers.push(res);
}
}
@@ -461,7 +474,7 @@ export class IGDBProvider implements MetadataProvider {
images,
};
context?.log("IGDB provider finished.");
context?.logger.info("IGDB provider finished.");
context?.progress(100);
return metadata;
@@ -469,7 +482,7 @@ export class IGDBProvider implements MetadataProvider {
async fetchCompany({
query,
createObject,
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata> {
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata | undefined> {
const response = await this.request<IGDBCompany>(
"companies",
`where name = "${query}"; fields *; limit 1;`,
@@ -503,6 +516,6 @@ export class IGDBProvider implements MetadataProvider {
return metadata;
}
throw new Error(`igdb failed to find publisher/developer ${query}`);
return undefined;
}
}
+7 -9
View File
@@ -16,6 +16,7 @@ import type { TaskRunContext } from "../tasks";
import taskHandler, { wrapTaskContext } from "../tasks";
import { randomUUID } from "crypto";
import { fuzzy } from "fast-fuzzy";
import { logger } from "~/server/internal/logging";
export class MissingMetadataProviderConfig extends Error {
private providerName: string;
@@ -89,7 +90,7 @@ export class MetadataHandler {
);
resolve(mappedResults);
} catch (e) {
console.warn(e);
logger.warn(e);
reject(e);
}
});
@@ -187,7 +188,7 @@ export class MetadataHandler {
taskGroup: "import:game",
acls: ["system:import:game:read"],
async run(context) {
const { progress, log } = context;
const { progress, logger } = context;
progress(0);
@@ -262,12 +263,12 @@ export class MetadataHandler {
});
progress(63);
log(`Successfully fetched all metadata.`);
log(`Importing objects...`);
logger.info(`Successfully fetched all metadata.`);
logger.info(`Importing objects...`);
await pullObjects();
log(`Finished game import.`);
logger.info(`Finished game import.`);
},
});
@@ -301,7 +302,7 @@ export class MetadataHandler {
);
}
} catch (e) {
console.warn(e);
logger.warn(e);
dumpObjects();
continue;
}
@@ -337,9 +338,6 @@ export class MetadataHandler {
return object;
}
// throw new Error(
// `No metadata provider found a ${databaseName} for "${query}"`,
// );
return undefined;
}
}
+2 -2
View File
@@ -44,7 +44,7 @@ export class ManualMetadataProvider implements MetadataProvider {
}
async fetchCompany(
_params: _FetchCompanyMetadataParams,
): Promise<CompanyMetadata> {
throw new Error("Method not implemented.");
): Promise<CompanyMetadata | undefined> {
return undefined;
}
}
+24 -14
View File
@@ -16,6 +16,7 @@ import { DateTime } from "luxon";
import * as cheerio from "cheerio";
import { type } from "arktype";
import type { TaskRunContext } from "../tasks";
import { logger } from "~/server/internal/logging";
interface PCGamingWikiParseRawPage {
parse: {
@@ -184,7 +185,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
let matches;
if ((matches = opencriticRegex.exec(url.pathname)) !== null) {
matches.forEach((match, _groupIndex) => {
// console.log(`Found match, group ${_groupIndex}: ${match}`);
// logger.log(`Found match, group ${_groupIndex}: ${match}`);
id = match;
});
}
@@ -199,7 +200,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
return url.pathname.replace("/games/", "").replace(/\/$/, "");
}
default: {
console.warn("Pcgamingwiki, unknown host", url.hostname);
logger.warn("Pcgamingwiki, unknown host", url.hostname);
return undefined;
}
}
@@ -223,7 +224,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
const href = reviewEle.attr("href");
if (!href) {
console.log(
logger.info(
`pcgamingwiki: failed to properly get review href for ${source}`,
);
return undefined;
@@ -232,7 +233,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
rating: reviewEle.text().trim(),
});
if (ratingObj instanceof type.errors) {
console.log(
logger.info(
"pcgamingwiki: failed to properly get review rating",
ratingObj.summary,
);
@@ -374,7 +375,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
{ id, name, publisher, developer, createObject }: _FetchGameMetadataParams,
context?: TaskRunContext,
): Promise<GameMetadata> {
context?.log("Using PCGamingWiki provider");
context?.logger.info("Using PCGamingWiki provider");
context?.progress(0);
const searchParams = new URLSearchParams({
@@ -397,13 +398,18 @@ export class PCGamingWikiProvider implements MetadataProvider {
const publishers: Company[] = [];
if (game.Publishers !== null) {
context?.log("Found publishers, importing...");
context?.logger.info("Found publishers, importing...");
const pubListClean = this.parseWikiStringArray(game.Publishers);
for (const pub of pubListClean) {
context?.log(`Importing "${pub}"...`);
context?.logger.info(`Importing publisher "${pub}"...`);
const res = await publisher(pub);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(`Failed to import publisher "${pub}"`);
continue;
}
context?.logger.info(`Imported publisher "${pub}"`);
// add to publishers
publishers.push(res);
}
}
@@ -412,12 +418,16 @@ export class PCGamingWikiProvider implements MetadataProvider {
const developers: Company[] = [];
if (game.Developers !== null) {
context?.log("Found developers, importing...");
context?.logger.info("Found developers, importing...");
const devListClean = this.parseWikiStringArray(game.Developers);
for (const dev of devListClean) {
context?.log(`Importing "${dev}"...`);
context?.logger.info(`Importing developer "${dev}"...`);
const res = await developer(dev);
if (res === undefined) continue;
if (res === undefined) {
context?.logger.warn(`Failed to import developer "${dev}"`);
continue;
}
context?.logger.info(`Imported developer "${dev}"`);
developers.push(res);
}
}
@@ -453,7 +463,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
images: [icon],
};
context?.log("PCGamingWiki provider finished.");
context?.logger.info("PCGamingWiki provider finished.");
context?.progress(100);
return metadata;
@@ -462,7 +472,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
async fetchCompany({
query,
createObject,
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata> {
}: _FetchCompanyMetadataParams): Promise<CompanyMetadata | undefined> {
const searchParams = new URLSearchParams({
action: "cargoquery",
tables: "Company",
@@ -496,6 +506,6 @@ export class PCGamingWikiProvider implements MetadataProvider {
return metadata;
}
throw new Error(`pcgamingwiki failed to find publisher/developer ${query}`);
return undefined;
}
}