From e30db0897d6ffa4bb87b1ee05d39b440a189d893 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:33:51 +0100 Subject: [PATCH] Added author in the search results for books --- src/api/apis/OpenLibraryAPI.ts | 11 ++++++++--- src/models/BookModel.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) 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; } }