diff --git a/client/components/modals/edit-tabs/Cover.vue b/client/components/modals/edit-tabs/Cover.vue index fb8a493d..4ac1f5b6 100644 --- a/client/components/modals/edit-tabs/Cover.vue +++ b/client/components/modals/edit-tabs/Cover.vue @@ -40,7 +40,7 @@ -
+ + +
+
+ +
+
+ +
+
+ +
+ Search +
+
+
+

No Covers Found

+ +

Preview Cover

@@ -97,7 +111,22 @@ export default { hasSearched: false, showLocalCovers: false, previewUpload: null, - selectedFile: null + selectedFile: null, + providers: [ + { + text: 'Google Books', + value: 'google' + }, + { + text: 'Open Library', + value: 'openlibrary' + }, + { + text: 'Audible', + value: 'audible' + } + ], + provider: 'google' } }, watch: { @@ -201,6 +230,7 @@ export default { this.imageUrl = this.book.cover || '' this.searchTitle = this.book.title || '' this.searchAuthor = this.book.authorFL || '' + this.provider = localStorage.getItem('book-provider') || 'openlibrary' }, removeCover() { if (!this.book.cover) { @@ -254,14 +284,24 @@ export default { this.isProcessing = false }, getSearchQuery() { - var searchQuery = `provider=openlibrary&title=${this.searchTitle}` + var searchQuery = `provider=${this.provider}&title=${this.searchTitle}` if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}` return searchQuery }, + persistProvider() { + try { + localStorage.setItem('book-provider', this.provider) + } catch (error) { + console.error('PersistProvider', error) + } + }, async submitSearchForm() { + // Store provider in local storage + this.persistProvider() + this.isProcessing = true var searchQuery = this.getSearchQuery() - var results = await this.$axios.$get(`/api/find/covers?${searchQuery}`).catch((error) => { + var results = await this.$axios.$get(`/api/search/covers?${searchQuery}`).catch((error) => { console.error('Failed', error) return [] }) diff --git a/client/components/modals/edit-tabs/Match.vue b/client/components/modals/edit-tabs/Match.vue index b0667b13..f082bc48 100644 --- a/client/components/modals/edit-tabs/Match.vue +++ b/client/components/modals/edit-tabs/Match.vue @@ -159,6 +159,13 @@ export default { } }, methods: { + persistProvider() { + try { + localStorage.setItem('book-provider', this.provider) + } catch (error) { + console.error('PersistProvider', error) + } + }, getSearchQuery() { var searchQuery = `provider=${this.provider}&fallbackTitleOnly=1&title=${this.searchTitle}` if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}` @@ -169,6 +176,7 @@ export default { this.$toast.warning('Search title is required') return } + this.persistProvider() this.runSearch() }, async runSearch() { @@ -177,7 +185,7 @@ export default { this.searchResults = [] this.isProcessing = true this.lastSearch = searchQuery - var results = await this.$axios.$get(`/api/find/search?${searchQuery}`).catch((error) => { + var results = await this.$axios.$get(`/api/search/books?${searchQuery}`).catch((error) => { console.error('Failed', error) return [] }) @@ -217,6 +225,7 @@ export default { } this.searchTitle = this.audiobook.book.title this.searchAuthor = this.audiobook.book.authorFL || '' + this.provider = localStorage.getItem('book-provider') || 'google' }, selectMatch(match) { this.selectedMatch = match diff --git a/server/ApiController.js b/server/ApiController.js index 1ce4f188..fcad04b6 100644 --- a/server/ApiController.js +++ b/server/ApiController.js @@ -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) { diff --git a/server/BookFinder.js b/server/BookFinder.js index 6ad856a0..c7f18f22 100644 --- a/server/BookFinder.js +++ b/server/BookFinder.js @@ -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') {