maintenance
This commit is contained in:
parent
846f7de184
commit
1d76bb8981
7 changed files with 80 additions and 55 deletions
|
|
@ -8,6 +8,12 @@ export class APIManager {
|
|||
this.apis = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the basic info for one query string and multiple APIs.
|
||||
*
|
||||
* @param query
|
||||
* @param apisToQuery
|
||||
*/
|
||||
async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> {
|
||||
console.debug(`MDB | api manager queried with "${query}"`);
|
||||
|
||||
|
|
@ -23,10 +29,21 @@ export class APIManager {
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries detailed information for a MediaTypeModel.
|
||||
*
|
||||
* @param item
|
||||
*/
|
||||
async queryDetailedInfo(item: MediaTypeModel): Promise<MediaTypeModel> {
|
||||
return await this.queryDetailedInfoById(item.id, item.dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries detailed info for an id from an API.
|
||||
*
|
||||
* @param id
|
||||
* @param apiName
|
||||
*/
|
||||
async queryDetailedInfoById(id: string, apiName: string): Promise<MediaTypeModel> {
|
||||
for (const api of this.apis) {
|
||||
if (api.apiName === apiName) {
|
||||
|
|
|
|||
|
|
@ -44,37 +44,37 @@ export class MALAPIManga extends APIModel {
|
|||
|
||||
for (const result of data.data) {
|
||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||
ret.push(
|
||||
new MangaModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
synopsis: result.synopsis,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
alternateTitles: result.titles?.map((x: any) => x.title) ?? [],
|
||||
year: result.year ?? result.published?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
url: result.url,
|
||||
id: result.mal_id,
|
||||
|
||||
genres: result.genres?.map((x: any) => x.name) ?? [],
|
||||
authors: result.authors?.map((x: any) => x.name) ?? [],
|
||||
chapters: result.chapters,
|
||||
volumes: result.volumes,
|
||||
onlineRating: result.score ?? 0,
|
||||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
|
||||
publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown',
|
||||
status: result.status,
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
lastWatched: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
} as MangaModel)
|
||||
)
|
||||
ret.push(
|
||||
new MangaModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
synopsis: result.synopsis,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
alternateTitles: result.titles?.map((x: any) => x.title) ?? [],
|
||||
year: result.year ?? result.published?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
url: result.url,
|
||||
id: result.mal_id,
|
||||
|
||||
genres: result.genres?.map((x: any) => x.name) ?? [],
|
||||
authors: result.authors?.map((x: any) => x.name) ?? [],
|
||||
chapters: result.chapters,
|
||||
volumes: result.volumes,
|
||||
onlineRating: result.score ?? 0,
|
||||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
|
||||
publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown',
|
||||
status: result.status,
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
lastWatched: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
} as MangaModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
this.apiDescription = 'A free API for books';
|
||||
this.apiUrl = 'https://openlibrary.org/';
|
||||
this.types = [MediaType.Book];
|
||||
}
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
|
@ -34,15 +34,15 @@ export class OpenLibraryAPI extends APIModel {
|
|||
const ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const result of data.docs) {
|
||||
ret.push(
|
||||
new BookModel({
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.first_publish_year,
|
||||
dataSource: this.apiName,
|
||||
id: result.key,
|
||||
} as BookModel)
|
||||
);
|
||||
ret.push(
|
||||
new BookModel({
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.first_publish_year,
|
||||
dataSource: this.apiName,
|
||||
id: result.key,
|
||||
} as BookModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -87,4 +87,4 @@ export class OpenLibraryAPI extends APIModel {
|
|||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue