From b856c1820738f0a698764bf37e6868ad385fd518 Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Mon, 3 Jun 2024 01:51:27 -0400 Subject: [PATCH 1/3] 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); From f488018f15ab70461045b7a122627836fa1bc3b8 Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Mon, 3 Jun 2024 01:55:31 -0400 Subject: [PATCH 2/3] Update OMDb urls to https --- src/api/apis/OMDbAPI.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 863c02b..e3806c9 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -17,7 +17,7 @@ export class OMDbAPI extends APIModel { this.plugin = plugin; this.apiName = 'OMDbAPI'; this.apiDescription = 'A free API for Movies, Series and Games.'; - this.apiUrl = 'http://www.omdbapi.com/'; + this.apiUrl = 'https://www.omdbapi.com/'; this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; this.typeMappings = new Map(); this.typeMappings.set('movie', 'movie'); @@ -32,7 +32,7 @@ export class OMDbAPI extends APIModel { throw Error(`MDB | OMDb ${this.apiName} API key missing.`); } - const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; + const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl); if (fetchData.status === 401) { @@ -110,7 +110,7 @@ export class OMDbAPI extends APIModel { throw Error(`MDB | OMDb ${this.apiName} API key missing.`); } - const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; + const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl); if (fetchData.status === 401) { From 642aa02937bb41df9762421e86ec2b921503ec91 Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Fri, 7 Jun 2024 16:08:17 -0400 Subject: [PATCH 3/3] remove extra logging --- src/api/apis/MobyGamesAPI.ts | 4 ++-- src/api/apis/OMDbAPI.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index c8a355b..7b8a47f 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -22,7 +22,7 @@ export class MobyGamesAPI extends APIModel { console.log(`MDB | api "${this.apiName}" queried by Title`); if(!this.plugin.settings.MobyGamesKey) { - throw Error(`MDB | MobyGames ${this.apiName} API key missing.`); + throw Error(`MDB | ${this.apiName} API key missing.`); } const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`; @@ -65,7 +65,7 @@ export class MobyGamesAPI extends APIModel { console.log(`MDB | api "${this.apiName}" queried by ID`); if(!this.plugin.settings.MobyGamesKey) { - throw Error(`MDB | MobyGames ${this.apiName} API key missing.`); + throw Error(`MDB | ${this.apiName} API key missing.`); } const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`; diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index e3806c9..b20dcbd 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -29,7 +29,7 @@ export class OMDbAPI extends APIModel { console.log(`MDB | api "${this.apiName}" queried by Title`); if(!this.plugin.settings.OMDbKey) { - throw Error(`MDB | OMDb ${this.apiName} API key missing.`); + throw Error(`MDB | ${this.apiName} API key missing.`); } const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; @@ -107,7 +107,7 @@ export class OMDbAPI extends APIModel { console.log(`MDB | api "${this.apiName}" queried by ID`); if(!this.plugin.settings.OMDbKey) { - throw Error(`MDB | OMDb ${this.apiName} API key missing.`); + throw Error(`MDB | ${this.apiName} API key missing.`); } const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;