Add:Select cover search provider, Add:Persist selected provider, Change:API routes for searching

This commit is contained in:
advplyr 2021-12-07 18:42:56 -06:00
parent bb1a5b2e6d
commit c5465ad8e0
4 changed files with 82 additions and 26 deletions

View file

@ -40,10 +40,6 @@ class ApiController {
}
init() {
this.router.get('/find/covers', this.findCovers.bind(this))
this.router.get('/find/:method', this.find.bind(this))
//
// Library Routes
//
@ -149,6 +145,12 @@ class ApiController {
this.router.delete('/backup/:id', BackupController.delete.bind(this))
this.router.post('/backup/upload', BackupController.upload.bind(this))
//
// Search Routes
//
this.router.get('/search/covers', this.findCovers.bind(this))
this.router.get('/search/books', this.findBooks.bind(this))
//
// Others
//
@ -174,16 +176,21 @@ class ApiController {
this.router.post('/syncUserAudiobookData', this.syncUserAudiobookData.bind(this))
}
async find(req, res) {
var provider = req.query.provider || 'google'
async findBooks(req, res) {
if (req.method === 'match') {
} else if (req.method === 'cover')
var provider = req.query.provider || 'google'
var title = req.query.title || ''
var author = req.query.author || ''
var results = await this.bookFinder.search(provider, title, author)
res.json(results)
}
findCovers(req, res) {
this.scanner.findCovers(req, res)
async findCovers(req, res) {
var query = req.query
var result = await this.bookFinder.findCovers(query.provider, query.title, query.author || null)
res.json(result)
}
authorize(req, res) {

View file

@ -147,7 +147,7 @@ class BookFinder {
return booksFiltered
}
async getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance) {
async getGoogleBooksResults(title, author) {
var books = await this.googleBooks.search(title, author)
if (this.verbose) Logger.debug(`GoogleBooks Book Search Results: ${books.length || 0}`)
if (books.errorCode) {
@ -158,7 +158,7 @@ class BookFinder {
return books
}
async getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance) {
async getAudibleResults(title, author) {
var books = await this.audible.search(title, author);
if (this.verbose) Logger.debug(`Audible Book Search Results: ${books.length || 0}`)
if (!books) return []
@ -172,9 +172,9 @@ class BookFinder {
Logger.debug(`Book Search: title: "${title}", author: "${author}", provider: ${provider}`)
if (provider === 'google') {
return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance)
return this.getGoogleBooksResults(title, author)
} else if (provider === 'audible') {
return this.getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance)
return this.getAudibleResults(title, author)
} else if (provider === 'libgen') {
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
} else if (provider === 'openlibrary') {