diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 3e7e09d..e2ba01d 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel { async searchByTitle(title: string): Promise { 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), ); } diff --git a/src/models/BookModel.ts b/src/models/BookModel.ts index f381d2e..183d402 100644 --- a/src/models/BookModel.ts +++ b/src/models/BookModel.ts @@ -56,6 +56,6 @@ export class BookModel extends MediaTypeModel { } getSummary(): string { - return this.englishTitle + ' (' + this.year + ')'; + return this.englishTitle + ' (' + this.year + ') - ' + this.author; } }