Added author in the search results for books

This commit is contained in:
ltctceplrm 2023-12-21 20:33:51 +01:00
parent d21ac66061
commit e30db0897d
2 changed files with 9 additions and 4 deletions

View file

@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel {
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried by Title`);
const searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`;
const titlesplit = title.split("++")
if(titlesplit.length !== 1 ){
var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(titlesplit[0])}&author=${encodeURIComponent(titlesplit[1])}`;
}
else{
var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`;
}
const fetchData = await fetch(searchUrl);
console.debug(fetchData);
if (fetchData.status !== 200) {
@ -41,6 +45,7 @@ export class OpenLibraryAPI extends APIModel {
year: result.first_publish_year,
dataSource: this.apiName,
id: result.key,
author: result.author_name ?? 'unknown',
} as BookModel),
);
}