Skip to content

Commit 00ba1d8

Browse files
Merge pull request #147 from ZackBoe/auth-required
MobyGames, OMDb: Don't search APIs that require keys if no key is present
2 parents c557bfe + 642aa02 commit 00ba1d8

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/api/apis/MobyGamesAPI.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class MobyGamesAPI extends APIModel {
2121
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2222
console.log(`MDB | api "${this.apiName}" queried by Title`);
2323

24+
if(!this.plugin.settings.MobyGamesKey) {
25+
throw Error(`MDB | ${this.apiName} API key missing.`);
26+
}
27+
2428
const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`;
2529
const fetchData = await requestUrl({
2630
url: searchUrl,
@@ -60,6 +64,10 @@ export class MobyGamesAPI extends APIModel {
6064
async getById(id: string): Promise<MediaTypeModel> {
6165
console.log(`MDB | api "${this.apiName}" queried by ID`);
6266

67+
if(!this.plugin.settings.MobyGamesKey) {
68+
throw Error(`MDB | ${this.apiName} API key missing.`);
69+
}
70+
6371
const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`;
6472
const fetchData = await requestUrl({
6573
url: searchUrl,

src/api/apis/OMDbAPI.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class OMDbAPI extends APIModel {
1717
this.plugin = plugin;
1818
this.apiName = 'OMDbAPI';
1919
this.apiDescription = 'A free API for Movies, Series and Games.';
20-
this.apiUrl = 'http://www.omdbapi.com/';
20+
this.apiUrl = 'https://www.omdbapi.com/';
2121
this.types = [MediaType.Movie, MediaType.Series, MediaType.Game];
2222
this.typeMappings = new Map<string, string>();
2323
this.typeMappings.set('movie', 'movie');
@@ -28,7 +28,11 @@ export class OMDbAPI extends APIModel {
2828
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2929
console.log(`MDB | api "${this.apiName}" queried by Title`);
3030

31-
const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
31+
if(!this.plugin.settings.OMDbKey) {
32+
throw Error(`MDB | ${this.apiName} API key missing.`);
33+
}
34+
35+
const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
3236
const fetchData = await fetch(searchUrl);
3337

3438
if (fetchData.status === 401) {
@@ -102,7 +106,11 @@ export class OMDbAPI extends APIModel {
102106
async getById(id: string): Promise<MediaTypeModel> {
103107
console.log(`MDB | api "${this.apiName}" queried by ID`);
104108

105-
const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
109+
if(!this.plugin.settings.OMDbKey) {
110+
throw Error(`MDB | ${this.apiName} API key missing.`);
111+
}
112+
113+
const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
106114
const fetchData = await fetch(searchUrl);
107115

108116
if (fetchData.status === 401) {

0 commit comments

Comments
 (0)