Added author in the search results for books
This commit is contained in:
parent
d21ac66061
commit
e30db0897d
2 changed files with 9 additions and 4 deletions
|
|
@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel {
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||||
|
const titlesplit = title.split("++")
|
||||||
const searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`;
|
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);
|
const fetchData = await fetch(searchUrl);
|
||||||
console.debug(fetchData);
|
console.debug(fetchData);
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
|
|
@ -41,6 +45,7 @@ export class OpenLibraryAPI extends APIModel {
|
||||||
year: result.first_publish_year,
|
year: result.first_publish_year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
id: result.key,
|
id: result.key,
|
||||||
|
author: result.author_name ?? 'unknown',
|
||||||
} as BookModel),
|
} as BookModel),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,6 @@ export class BookModel extends MediaTypeModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSummary(): string {
|
getSummary(): string {
|
||||||
return this.englishTitle + ' (' + this.year + ')';
|
return this.englishTitle + ' (' + this.year + ') - ' + this.author;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue