Skip to content

Commit e8e262e

Browse files
committed
small fixes
1 parent 00ba1d8 commit e8e262e

File tree

9 files changed

+63
-91
lines changed

9 files changed

+63
-91
lines changed

src/api/apis/BoardGameGeekAPI.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class BoardGameGeekAPI extends APIModel {
2727
});
2828

2929
if (fetchData.status !== 200) {
30-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
30+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
3131
}
3232

3333
const data = fetchData.text;
3434
const response = new window.DOMParser().parseFromString(data, 'text/xml');
3535

36-
console.debug(response);
36+
// console.debug(response);
3737

3838
const ret: MediaTypeModel[] = [];
3939

@@ -65,12 +65,12 @@ export class BoardGameGeekAPI extends APIModel {
6565
});
6666

6767
if (fetchData.status !== 200) {
68-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
68+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
6969
}
7070

7171
const data = fetchData.text;
7272
const response = new window.DOMParser().parseFromString(data, 'text/xml');
73-
console.debug(response);
73+
// console.debug(response);
7474

7575
const boardgame = response.querySelector('boardgame')!;
7676
const title = boardgame.querySelector('name[primary=true]')!.textContent!;
@@ -84,7 +84,7 @@ export class BoardGameGeekAPI extends APIModel {
8484
const playtime = (boardgame.querySelector('playingtime')?.textContent ?? 'unknown') + ' minutes';
8585
const publishers = Array.from(boardgame.querySelectorAll('boardgamepublisher')).map(n => n!.textContent!);
8686

87-
const model = new BoardGameModel({
87+
return new BoardGameModel({
8888
title: title,
8989
englishTitle: title,
9090
year: year === '0' ? '' : year,
@@ -108,7 +108,5 @@ export class BoardGameGeekAPI extends APIModel {
108108
personalRating: 0,
109109
},
110110
} as BoardGameModel);
111-
112-
return model;
113111
}
114112
}

src/api/apis/MALAPI.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export class MALAPI extends APIModel {
3131
const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`;
3232

3333
const fetchData = await fetch(searchUrl);
34-
console.debug(fetchData);
34+
// console.debug(fetchData);
3535
if (fetchData.status !== 200) {
36-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
36+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
3737
}
3838
const data = await fetchData.json();
3939

40-
console.debug(data);
40+
// console.debug(data);
4141

4242
const ret: MediaTypeModel[] = [];
4343

@@ -90,16 +90,16 @@ export class MALAPI extends APIModel {
9090
const fetchData = await fetch(searchUrl);
9191

9292
if (fetchData.status !== 200) {
93-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
93+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
9494
}
9595

9696
const data = await fetchData.json();
97-
console.debug(data);
97+
// console.debug(data);
9898
const result = data.data;
9999

100100
const type = this.typeMappings.get(result.type?.toLowerCase());
101101
if (type === undefined) {
102-
const model = new MovieModel({
102+
return new MovieModel({
103103
subType: '',
104104
title: result.title,
105105
englishTitle: result.title_english ?? result.title,
@@ -128,12 +128,10 @@ export class MALAPI extends APIModel {
128128
personalRating: 0,
129129
},
130130
} as MovieModel);
131-
132-
return model;
133131
}
134132

135133
if (type === 'movie' || type === 'special') {
136-
const model = new MovieModel({
134+
return new MovieModel({
137135
subType: type,
138136
title: result.title,
139137
englishTitle: result.title_english ?? result.title,
@@ -162,10 +160,8 @@ export class MALAPI extends APIModel {
162160
personalRating: 0,
163161
},
164162
} as MovieModel);
165-
166-
return model;
167163
} else if (type === 'series' || type === 'ova') {
168-
const model = new SeriesModel({
164+
return new SeriesModel({
169165
subType: type,
170166
title: result.title,
171167
englishTitle: result.title_english ?? result.title,
@@ -195,8 +191,6 @@ export class MALAPI extends APIModel {
195191
personalRating: 0,
196192
},
197193
} as SeriesModel);
198-
199-
return model;
200194
}
201195

202196
return;

src/api/apis/MALAPIManga.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ export class MALAPIManga extends APIModel {
3232
const searchUrl = `https://api.jikan.moe/v4/manga?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`;
3333

3434
const fetchData = await fetch(searchUrl);
35-
console.debug(fetchData);
35+
// console.debug(fetchData);
3636
if (fetchData.status !== 200) {
37-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
37+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
3838
}
3939
const data = await fetchData.json();
4040

41-
console.debug(data);
41+
// console.debug(data);
4242

4343
const ret: MediaTypeModel[] = [];
4444

@@ -87,15 +87,15 @@ export class MALAPIManga extends APIModel {
8787
const fetchData = await fetch(searchUrl);
8888

8989
if (fetchData.status !== 200) {
90-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
90+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
9191
}
9292

9393
const data = await fetchData.json();
94-
console.debug(data);
94+
// console.debug(data);
9595
const result = data.data;
9696

9797
const type = this.typeMappings.get(result.type?.toLowerCase());
98-
const model = new MangaModel({
98+
return new MangaModel({
9999
subType: type,
100100
title: result.title,
101101
englishTitle: result.title_english ?? result.title,
@@ -124,7 +124,5 @@ export class MALAPIManga extends APIModel {
124124
personalRating: 0,
125125
},
126126
} as MangaModel);
127-
128-
return model;
129127
}
130128
}

src/api/apis/MobyGamesAPI.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ 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.`);
24+
if (!this.plugin.settings.MobyGamesKey) {
25+
throw Error(`MDB | API key for ${this.apiName} missing.`);
2626
}
2727

2828
const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`;
2929
const fetchData = await requestUrl({
3030
url: searchUrl,
3131
});
3232

33-
console.debug(fetchData);
33+
// console.debug(fetchData);
3434

3535
if (fetchData.status === 401) {
3636
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
@@ -39,11 +39,11 @@ export class MobyGamesAPI extends APIModel {
3939
throw Error(`MDB | Too many requests for ${this.apiName}, you've exceeded your API quota.`);
4040
}
4141
if (fetchData.status !== 200) {
42-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
42+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
4343
}
4444

4545
const data = await fetchData.json;
46-
console.debug(data);
46+
// console.debug(data);
4747
const ret: MediaTypeModel[] = [];
4848
for (const result of data.games) {
4949
ret.push(
@@ -64,8 +64,8 @@ export class MobyGamesAPI extends APIModel {
6464
async getById(id: string): Promise<MediaTypeModel> {
6565
console.log(`MDB | api "${this.apiName}" queried by ID`);
6666

67-
if(!this.plugin.settings.MobyGamesKey) {
68-
throw Error(`MDB | ${this.apiName} API key missing.`);
67+
if (!this.plugin.settings.MobyGamesKey) {
68+
throw Error(`MDB | API key for ${this.apiName} missing.`);
6969
}
7070

7171
const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`;
@@ -75,14 +75,14 @@ export class MobyGamesAPI extends APIModel {
7575
console.debug(fetchData);
7676

7777
if (fetchData.status !== 200) {
78-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
78+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
7979
}
8080

8181
const data = await fetchData.json;
82-
console.debug(data);
82+
// console.debug(data);
8383
const result = data.games[0];
8484

85-
const model = new GameModel({
85+
return new GameModel({
8686
type: MediaType.Game,
8787
title: result.title,
8888
englishTitle: result.title,
@@ -105,7 +105,5 @@ export class MobyGamesAPI extends APIModel {
105105
personalRating: 0,
106106
},
107107
} as GameModel);
108-
109-
return model;
110108
}
111109
}

src/api/apis/MusicBrainzAPI.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export class MusicBrainzAPI extends APIModel {
3131
},
3232
});
3333

34-
console.debug(fetchData);
34+
// console.debug(fetchData);
3535

3636
if (fetchData.status !== 200) {
37-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
37+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
3838
}
3939

4040
const data = await fetchData.json;
41-
console.debug(data);
41+
// console.debug(data);
4242
const ret: MediaTypeModel[] = [];
4343

4444
for (const result of data['release-groups']) {
@@ -74,14 +74,12 @@ export class MusicBrainzAPI extends APIModel {
7474
});
7575

7676
if (fetchData.status !== 200) {
77-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
77+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
7878
}
7979

80-
const data = await fetchData.json;
81-
console.debug(data);
82-
const result = data;
80+
const result = await fetchData.json;
8381

84-
const model = new MusicReleaseModel({
82+
return new MusicReleaseModel({
8583
type: 'musicRelease',
8684
title: result.title,
8785
englishTitle: result.title,
@@ -100,7 +98,5 @@ export class MusicBrainzAPI extends APIModel {
10098
personalRating: 0,
10199
},
102100
} as MusicReleaseModel);
103-
104-
return model;
105101
}
106102
}

src/api/apis/OMDbAPI.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class OMDbAPI extends APIModel {
2828
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2929
console.log(`MDB | api "${this.apiName}" queried by Title`);
3030

31-
if(!this.plugin.settings.OMDbKey) {
32-
throw Error(`MDB | ${this.apiName} API key missing.`);
31+
if (!this.plugin.settings.OMDbKey) {
32+
throw Error(`MDB | API key for ${this.apiName} missing.`);
3333
}
3434

3535
const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
@@ -39,7 +39,7 @@ export class OMDbAPI extends APIModel {
3939
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
4040
}
4141
if (fetchData.status !== 200) {
42-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
42+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
4343
}
4444

4545
const data = await fetchData.json();
@@ -55,7 +55,7 @@ export class OMDbAPI extends APIModel {
5555
return [];
5656
}
5757

58-
console.debug(data.Search);
58+
// console.debug(data.Search);
5959

6060
const ret: MediaTypeModel[] = [];
6161

@@ -106,8 +106,8 @@ export class OMDbAPI extends APIModel {
106106
async getById(id: string): Promise<MediaTypeModel> {
107107
console.log(`MDB | api "${this.apiName}" queried by ID`);
108108

109-
if(!this.plugin.settings.OMDbKey) {
110-
throw Error(`MDB | ${this.apiName} API key missing.`);
109+
if (!this.plugin.settings.OMDbKey) {
110+
throw Error(`MDB | API key for ${this.apiName} missing.`);
111111
}
112112

113113
const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
@@ -117,7 +117,7 @@ export class OMDbAPI extends APIModel {
117117
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
118118
}
119119
if (fetchData.status !== 200) {
120-
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
120+
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
121121
}
122122

123123
const result = await fetchData.json();
@@ -133,7 +133,7 @@ export class OMDbAPI extends APIModel {
133133
}
134134

135135
if (type === 'movie') {
136-
const model = new MovieModel({
136+
return new MovieModel({
137137
type: type,
138138
title: result.Title,
139139
englishTitle: result.Title,
@@ -162,10 +162,8 @@ export class OMDbAPI extends APIModel {
162162
personalRating: 0,
163163
},
164164
} as MovieModel);
165-
166-
return model;
167165
} else if (type === 'series') {
168-
const model = new SeriesModel({
166+
return new SeriesModel({
169167
type: type,
170168
title: result.Title,
171169
englishTitle: result.Title,
@@ -196,10 +194,8 @@ export class OMDbAPI extends APIModel {
196194
personalRating: 0,
197195
},
198196
} as SeriesModel);
199-
200-
return model;
201197
} else if (type === 'game') {
202-
const model = new GameModel({
198+
return new GameModel({
203199
type: type,
204200
title: result.Title,
205201
englishTitle: result.Title,
@@ -222,8 +218,6 @@ export class OMDbAPI extends APIModel {
222218
personalRating: 0,
223219
},
224220
} as GameModel);
225-
226-
return model;
227221
}
228222

229223
return;

0 commit comments

Comments
 (0)