feat: ratings ui, import giantbomb ratings

This commit is contained in:
DecDuck
2025-05-30 22:07:50 +10:00
parent 185f37f135
commit 3fbe514f65
7 changed files with 64 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ import type {
GameMetadata,
_FetchCompanyMetadataParams,
CompanyMetadata,
GameMetadataRating,
} from "./types";
import axios, { type AxiosRequestConfig } from "axios";
import TurndownService from "turndown";
@@ -58,6 +59,17 @@ interface GameResult {
tags: string; // If it's "All Images", art, otherwise screenshot
original: string;
}>;
reviews: Array<{
api_detail_url: string;
}>;
}
interface ReviewResult {
deck: string;
score: number; // Out of 5
reviewer: string;
site_detail_url: string;
}
interface CompanySearchResult {
@@ -198,6 +210,21 @@ export class GiantBombProvider implements MetadataProvider {
}-${gameData.expected_release_day ?? 1}`,
).toJSDate();
const reviews: GameMetadataRating[] = [];
for (const { api_detail_url } of gameData.reviews) {
const reviewId = api_detail_url.split("/").at(-2);
if (!reviewId) continue;
const review = await this.request<ReviewResult>("review", reviewId, {});
console.log(review.data);
reviews.push({
metadataSource: MetadataSource.GiantBomb,
metadataId: reviewId,
mReviewCount: 1,
mReviewRating: review.data.results.score / 5,
mReviewHref: review.data.results.site_detail_url,
});
}
const metadata: GameMetadata = {
id: gameData.guid,
name: gameData.name,
@@ -207,7 +234,7 @@ export class GiantBombProvider implements MetadataProvider {
tags: [],
reviews: [],
reviews,
publishers,
developers,

View File

@@ -355,8 +355,11 @@ export class IGDBProvider implements MetadataProvider {
const response = await this.request<IGDBGameFull>("games", body);
for (let i = 0; i < response.length; i++) {
const currentGame = response[i];
if(!currentGame) continue;
let iconRaw;
const cover = response[i].cover;
const cover = currentGame.cover;
if (cover !== undefined) {
iconRaw = await this.getCoverURL(cover);
} else {
@@ -366,7 +369,7 @@ export class IGDBProvider implements MetadataProvider {
let banner = "";
const images = [icon];
for (const art of response[i]?.artworks ?? []) {
for (const art of currentGame.artworks ?? []) {
// if banner not set
if (banner.length <= 0) {
banner = createObject(await this.getArtworkURL(art));
@@ -378,7 +381,7 @@ export class IGDBProvider implements MetadataProvider {
const publishers: Company[] = [];
const developers: Company[] = [];
for (const involvedCompany of response[i]?.involved_companies ?? []) {
for (const involvedCompany of currentGame.involved_companies ?? []) {
// get details about the involved company
const involved_company_response =
await this.request<IGDBInvolvedCompany>(
@@ -408,13 +411,13 @@ export class IGDBProvider implements MetadataProvider {
}
}
const firstReleaseDate = response[i].first_release_date;
const firstReleaseDate = currentGame.first_release_date;
return {
id: "" + response[i].id,
name: response[i].name,
shortDescription: this.trimMessage(response[i].summary, 280),
description: response[i].summary,
shortDescription: this.trimMessage(currentGame.summary, 280),
description: currentGame.summary,
released:
firstReleaseDate === undefined
? new Date()
@@ -422,18 +425,18 @@ export class IGDBProvider implements MetadataProvider {
reviews: [
{
metadataId: "" + response[i].id,
metadataId: "" + currentGame.id,
metadataSource: MetadataSource.IGDB,
mReviewCount: response[i]?.total_rating_count ?? 0,
mReviewRating: (response[i]?.total_rating ?? 0) / 100,
mReviewHref: response[i].url,
mReviewCount: currentGame.total_rating_count ?? 0,
mReviewRating: (currentGame.total_rating ?? 0) / 100,
mReviewHref: currentGame.url,
},
],
publishers: [],
developers: [],
tags: await this.getGenres(response[i].genres),
tags: await this.getGenres(currentGame.genres),
icon,
bannerId: banner,