Merge pull request #147 from ZackBoe/auth-required
MobyGames, OMDb: Don't search APIs that require keys if no key is present
This commit is contained in:
commit
00ba1d85ed
2 changed files with 19 additions and 3 deletions
|
|
@ -21,6 +21,10 @@ export class MobyGamesAPI extends APIModel {
|
|||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
if(!this.plugin.settings.MobyGamesKey) {
|
||||
throw Error(`MDB | ${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<MediaTypeModel> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
if(!this.plugin.settings.MobyGamesKey) {
|
||||
throw Error(`MDB | ${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,
|
||||
|
|
|
|||
|
|
@ -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<string, string>();
|
||||
this.typeMappings.set('movie', 'movie');
|
||||
|
|
@ -28,7 +28,11 @@ export class OMDbAPI extends APIModel {
|
|||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
if(!this.plugin.settings.OMDbKey) {
|
||||
throw Error(`MDB | ${this.apiName} API key missing.`);
|
||||
}
|
||||
|
||||
const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
const fetchData = await fetch(searchUrl);
|
||||
|
||||
if (fetchData.status === 401) {
|
||||
|
|
@ -102,7 +106,11 @@ export class OMDbAPI extends APIModel {
|
|||
async getById(id: string): Promise<MediaTypeModel> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
if(!this.plugin.settings.OMDbKey) {
|
||||
throw Error(`MDB | ${this.apiName} API key missing.`);
|
||||
}
|
||||
|
||||
const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
const fetchData = await fetch(searchUrl);
|
||||
|
||||
if (fetchData.status === 401) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue