mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 16:22:39 +10:00
cleanup giantbomb provider
This commit is contained in:
@ -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 =
|
||||||
|
|||||||
Reference in New Issue
Block a user