mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 00:02:37 +10:00
* feat: move game import to new task system * fix: sizing issue with new task UI * fix: lint * feat: add pcgamingwiki task
This commit is contained in:
@ -12,6 +12,7 @@ import type {
|
||||
import axios, { type AxiosRequestConfig } from "axios";
|
||||
import TurndownService from "turndown";
|
||||
import { DateTime } from "luxon";
|
||||
import type { TaskRunContext } from "../tasks";
|
||||
|
||||
interface GiantBombResponseType<T> {
|
||||
error: "OK" | string;
|
||||
@ -164,12 +165,12 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
|
||||
return mapped;
|
||||
}
|
||||
async fetchGame({
|
||||
id,
|
||||
publisher,
|
||||
developer,
|
||||
createObject,
|
||||
}: _FetchGameMetadataParams): Promise<GameMetadata> {
|
||||
async fetchGame(
|
||||
{ id, publisher, developer, createObject }: _FetchGameMetadataParams,
|
||||
context?: TaskRunContext,
|
||||
): Promise<GameMetadata> {
|
||||
context?.log("Using GiantBomb provider");
|
||||
|
||||
const result = await this.request<GameResult>("game", id, {});
|
||||
const gameData = result.data.results;
|
||||
|
||||
@ -180,21 +181,29 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
const publishers: Company[] = [];
|
||||
if (gameData.publishers) {
|
||||
for (const pub of gameData.publishers) {
|
||||
context?.log(`Importing publisher "${pub.name}"`);
|
||||
|
||||
const res = await publisher(pub.name);
|
||||
if (res === undefined) continue;
|
||||
publishers.push(res);
|
||||
}
|
||||
}
|
||||
|
||||
context?.progress(35);
|
||||
|
||||
const developers: Company[] = [];
|
||||
if (gameData.developers) {
|
||||
for (const dev of gameData.developers) {
|
||||
context?.log(`Importing developer "${dev.name}"`);
|
||||
|
||||
const res = await developer(dev.name);
|
||||
if (res === undefined) continue;
|
||||
developers.push(res);
|
||||
}
|
||||
}
|
||||
|
||||
context?.progress(70);
|
||||
|
||||
const icon = createObject(gameData.image.icon_url);
|
||||
const banner = createObject(gameData.image.screen_large_url);
|
||||
|
||||
@ -202,6 +211,8 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
|
||||
const images = [banner, ...imageURLs.map(createObject)];
|
||||
|
||||
context?.log(`Found all images. Total of ${images.length + 1}.`);
|
||||
|
||||
const releaseDate = gameData.original_release_date
|
||||
? DateTime.fromISO(gameData.original_release_date).toJSDate()
|
||||
: DateTime.fromISO(
|
||||
@ -210,8 +221,11 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
}-${gameData.expected_release_day ?? 1}`,
|
||||
).toJSDate();
|
||||
|
||||
context?.progress(85);
|
||||
|
||||
const reviews: GameMetadataRating[] = [];
|
||||
if (gameData.reviews) {
|
||||
context?.log("Found reviews, importing...");
|
||||
for (const { api_detail_url } of gameData.reviews) {
|
||||
const reviewId = api_detail_url.split("/").at(-2);
|
||||
if (!reviewId) continue;
|
||||
@ -225,6 +239,7 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const metadata: GameMetadata = {
|
||||
id: gameData.guid,
|
||||
name: gameData.name,
|
||||
@ -245,6 +260,9 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
images,
|
||||
};
|
||||
|
||||
context?.log("GiantBomb provider finished.");
|
||||
context?.progress(100);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
async fetchCompany({
|
||||
|
||||
Reference in New Issue
Block a user