From b856c1820738f0a698764bf37e6868ad385fd518 Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Mon, 3 Jun 2024 01:51:27 -0400 Subject: [PATCH] Don't search APIs that require keys if no key is present --- src/api/apis/MobyGamesAPI.ts | 8 ++++++++ src/api/apis/OMDbAPI.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index adbefb2..c8a355b 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -21,6 +21,10 @@ export class MobyGamesAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); + if(!this.plugin.settings.MobyGamesKey) { + throw Error(`MDB | MobyGames ${this.apiName} API key missing.`); + } + const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`; const fetchData = await requestUrl({ url: searchUrl, @@ -60,6 +64,10 @@ export class MobyGamesAPI extends APIModel { async getById(id: string): Promise { console.log(`MDB | api "${this.apiName}" queried by ID`); + if(!this.plugin.settings.MobyGamesKey) { + throw Error(`MDB | MobyGames ${this.apiName} API key missing.`); + } + const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`; const fetchData = await requestUrl({ url: searchUrl, diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 13308f6..863c02b 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -28,6 +28,10 @@ export class OMDbAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); + if(!this.plugin.settings.OMDbKey) { + throw Error(`MDB | OMDb ${this.apiName} API key missing.`); + } + const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl); @@ -102,6 +106,10 @@ export class OMDbAPI extends APIModel { async getById(id: string): Promise { console.log(`MDB | api "${this.apiName}" queried by ID`); + if(!this.plugin.settings.OMDbKey) { + throw Error(`MDB | OMDb ${this.apiName} API key missing.`); + } + const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl);