mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 17:54:44 +10:00
make pcgamig wiki types match api return
This commit is contained in:
@@ -19,26 +19,26 @@ interface PCGamingWikiPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface PCGamingWikiSearchStub extends PCGamingWikiPage {
|
interface PCGamingWikiSearchStub extends PCGamingWikiPage {
|
||||||
"Cover URL"?: string;
|
"Cover URL": string | null;
|
||||||
Released?: string;
|
Released: string | null;
|
||||||
Released__precision?: string;
|
Released__precision: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PCGamingWikiGame extends PCGamingWikiSearchStub {
|
interface PCGamingWikiGame extends PCGamingWikiSearchStub {
|
||||||
Developers?: string;
|
Developers: string | null;
|
||||||
Genres?: string;
|
Genres: string | null;
|
||||||
Publishers?: string;
|
Publishers: string | null;
|
||||||
Themes?: string;
|
Themes: string | null;
|
||||||
Series?: string;
|
Series: string | null;
|
||||||
Modes?: string;
|
Modes: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PCGamingWikiCompany extends PCGamingWikiPage {
|
interface PCGamingWikiCompany extends PCGamingWikiPage {
|
||||||
Parent?: string;
|
Parent: string | null;
|
||||||
Founded?: string;
|
Founded: string | null;
|
||||||
Website?: string;
|
Website: string | null;
|
||||||
Founded__precision?: string;
|
Founded__precision: string | null;
|
||||||
Defunct__precision?: string;
|
Defunct__precision: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PCGamingWikiCargoResult<T> {
|
interface PCGamingWikiCargoResult<T> {
|
||||||
@@ -94,16 +94,6 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private markNullUndefined<T extends Record<string, any>>(obj: T): T {
|
|
||||||
// TODO: fix types above and make everything nullable instead of possibly undefined, better then this, maybe?
|
|
||||||
|
|
||||||
const result = structuredClone(obj);
|
|
||||||
for (const [key, value] of Object.entries(result)) {
|
|
||||||
if (value === null) delete result[key];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async search(query: string) {
|
async search(query: string) {
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
action: "cargoquery",
|
action: "cargoquery",
|
||||||
@@ -117,7 +107,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
const res = await this.request<PCGamingWikiSearchStub>(searchParams);
|
const res = await this.request<PCGamingWikiSearchStub>(searchParams);
|
||||||
|
|
||||||
const mapped = res.data.cargoquery.map((result) => {
|
const mapped = res.data.cargoquery.map((result) => {
|
||||||
const game = this.markNullUndefined(result.title);
|
const game = result.title;
|
||||||
|
|
||||||
const metadata: GameMetadataSearchResult = {
|
const metadata: GameMetadataSearchResult = {
|
||||||
id: game.PageID,
|
id: game.PageID,
|
||||||
@@ -125,7 +115,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
icon: game["Cover URL"] ?? "",
|
icon: game["Cover URL"] ?? "",
|
||||||
description: "", // TODO: need to render the `Introduction` template somehow (or we could just hardcode it)
|
description: "", // TODO: need to render the `Introduction` template somehow (or we could just hardcode it)
|
||||||
year:
|
year:
|
||||||
game.Released !== undefined && game.Released.length > 0
|
game.Released !== null && game.Released.length > 0
|
||||||
? moment(game.Released).year()
|
? moment(game.Released).year()
|
||||||
: 0,
|
: 0,
|
||||||
};
|
};
|
||||||
@@ -177,7 +167,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
const game = res.data.cargoquery[0].title;
|
const game = res.data.cargoquery[0].title;
|
||||||
|
|
||||||
const publishers: Publisher[] = [];
|
const publishers: Publisher[] = [];
|
||||||
if (game.Publishers !== undefined) {
|
if (game.Publishers !== null) {
|
||||||
const pubListClean = this.parseCompanyStr(game.Publishers);
|
const pubListClean = this.parseCompanyStr(game.Publishers);
|
||||||
for (const pub of pubListClean) {
|
for (const pub of pubListClean) {
|
||||||
publishers.push(await publisher(pub));
|
publishers.push(await publisher(pub));
|
||||||
@@ -185,7 +175,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const developers: Developer[] = [];
|
const developers: Developer[] = [];
|
||||||
if (game.Developers !== undefined) {
|
if (game.Developers !== null) {
|
||||||
const devListClean = this.parseCompanyStr(game.Developers);
|
const devListClean = this.parseCompanyStr(game.Developers);
|
||||||
for (const dev of devListClean) {
|
for (const dev of devListClean) {
|
||||||
developers.push(await developer(dev));
|
developers.push(await developer(dev));
|
||||||
@@ -193,7 +183,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const icon =
|
const icon =
|
||||||
game["Cover URL"] !== undefined
|
game["Cover URL"] !== null
|
||||||
? createObject(game["Cover URL"])
|
? createObject(game["Cover URL"])
|
||||||
: createObject(jdenticon.toPng(name, 512));
|
: createObject(jdenticon.toPng(name, 512));
|
||||||
|
|
||||||
@@ -241,7 +231,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
const icon = createObject(jdenticon.toPng(query, 512));
|
const icon = createObject(jdenticon.toPng(query, 512));
|
||||||
|
|
||||||
for (let i = 0; i < res.data.cargoquery.length; i++) {
|
for (let i = 0; i < res.data.cargoquery.length; i++) {
|
||||||
const company = this.markNullUndefined(res.data.cargoquery[i].title);
|
const company = res.data.cargoquery[i].title;
|
||||||
|
|
||||||
const metadata: PublisherMetadata = {
|
const metadata: PublisherMetadata = {
|
||||||
id: company.PageID,
|
id: company.PageID,
|
||||||
|
|||||||
Reference in New Issue
Block a user