diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index fb6351d..3afe47f 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -151,7 +151,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: result.Poster ?? '', + image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '', released: true, streamingServices: [], @@ -181,7 +181,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: result.Poster ?? '', + image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '', released: true, streamingServices: [], @@ -209,7 +209,7 @@ export class OMDbAPI extends APIModel { publishers: [], genres: result.Genre?.split(', ') ?? [], onlineRating: Number.parseFloat(result.imdbRating ?? 0), - image: result.Poster ?? '', + image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '', released: true, releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', diff --git a/src/api/apis/SteamAPI.ts b/src/api/apis/SteamAPI.ts index d3f7c8f..504cc25 100644 --- a/src/api/apis/SteamAPI.ts +++ b/src/api/apis/SteamAPI.ts @@ -4,6 +4,7 @@ import { GameModel } from '../../models/GameModel'; import type { MediaTypeModel } from '../../models/MediaTypeModel'; import { MediaType } from '../../utils/MediaType'; import { APIModel } from '../APIModel'; +import { imageUrlExists } from '../../utils/Utils'; export class SteamAPI extends APIModel { plugin: MediaDbPlugin; @@ -85,6 +86,16 @@ export class SteamAPI extends APIModel { // console.debug(result); + // Check if a poster version of the image exists, else use the header image + const imageUrl = `https://steamcdn-a.akamaihd.net/steam/apps/${result.steam_appid}/library_600x900_2x.jpg`; + const exists = await imageUrlExists(imageUrl); + let finalimageurl; + if (exists) { + finalimageurl = imageUrl; + } else { + finalimageurl = result.header_image ?? ''; + } + return new GameModel({ type: MediaType.Game, title: result.name, @@ -98,7 +109,7 @@ export class SteamAPI extends APIModel { publishers: result.publishers, genres: result.genres?.map((x: any) => x.description) ?? [], onlineRating: Number.parseFloat(result.metacritic?.score ?? 0), - image: result.header_image ?? '', + image: finalimageurl ?? '', released: !result.release_date?.coming_soon, releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown', diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 7950b15..8a28f04 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -234,3 +234,19 @@ export async function useTemplaterPluginInFile(app: App, file: TFile): Promise = { [K in keyof T as T[K] extends Function ? never : K]?: T[K]; }; + +// Checks if a given URL points to an existing image (status 200), or returns false for 404/other errors. + +export async function imageUrlExists(url: string): Promise { + try { + // @ts-ignore + const response = await requestUrl({ + url, + method: 'HEAD', + throw: false, + }); + return response.status === 200; + } catch { + return false; + } +}