cleanup giantbomb provider

This commit is contained in:
Huskydog9988
2025-03-10 17:47:47 -04:00
parent d2b485456a
commit 4b4e067fac

View File

@ -74,13 +74,14 @@ interface CompanySearchResult {
}; };
} }
// Api Docs: https://www.giantbomb.com/api/
export class GiantBombProvider implements MetadataProvider { export class GiantBombProvider implements MetadataProvider {
private apikey: string; private apikey: string;
private turndown: TurndownService; private turndown: TurndownService;
constructor() { constructor() {
const apikey = process.env.GIANT_BOMB_API_KEY; const apikey = process.env.GIANT_BOMB_API_KEY;
if (!apikey) throw new MissingMetadataProviderApiKey("GiantBomb"); if (!apikey) throw new MissingMetadataProviderApiKey(this.name());
this.apikey = apikey; this.apikey = apikey;
@ -96,18 +97,14 @@ export class GiantBombProvider implements MetadataProvider {
private async request<T>( private async request<T>(
resource: string, resource: string,
url: string, url: string,
query: { [key: string]: string | Array<string> }, query: { [key: string]: string },
options?: AxiosRequestConfig options?: AxiosRequestConfig
) { ) {
const queryOptions = { ...query, api_key: this.apikey, format: "json" }; const queryString = new URLSearchParams({
const queryString = Object.entries(queryOptions) ...query,
.map(([key, value]) => { api_key: this.apikey,
if (Array.isArray(value)) { format: "json",
return `${key}=${value.map(encodeURIComponent).join(",")}`; }).toString();
}
return `${key}=${encodeURIComponent(value)}`;
})
.join("&");
const finalURL = `https://www.giantbomb.com/api/${resource}/${url}?${queryString}`; const finalURL = `https://www.giantbomb.com/api/${resource}/${url}?${queryString}`;
@ -134,7 +131,7 @@ export class GiantBombProvider implements MetadataProvider {
async search(query: string): Promise<GameMetadataSearchResult[]> { async search(query: string): Promise<GameMetadataSearchResult[]> {
const results = await this.request<Array<GameSearchResult>>("search", "", { const results = await this.request<Array<GameSearchResult>>("search", "", {
query: query, query: query,
resources: ["game"], resources: ["game"].join(","),
}); });
const mapped = results.data.results.map((result) => { const mapped = results.data.results.map((result) => {
const date = const date =