From 2d9035d90bd08f2f48e18aac5013aace2d691c44 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 12 Dec 2022 17:45:51 -0600 Subject: [PATCH] Update get tags route and revert podcast/books search route --- client/components/modals/AccountModal.vue | 4 +-- client/components/modals/item/tabs/Cover.vue | 13 ++++--- client/components/modals/item/tabs/Match.vue | 6 ++-- server/controllers/SearchController.js | 38 ++++++++++---------- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/client/components/modals/AccountModal.vue b/client/components/modals/AccountModal.vue index 6ea989cb..82045d51 100644 --- a/client/components/modals/AccountModal.vue +++ b/client/components/modals/AccountModal.vue @@ -201,8 +201,8 @@ export default { this.loadingTags = true this.$axios .$get(`/api/tags`) - .then((tags) => { - this.tags = tags + .then((res) => { + this.tags = res.tags this.loadingTags = false }) .catch((error) => { diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 529a06e5..5b866b07 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -303,11 +303,14 @@ export default { this.persistProvider() this.isProcessing = true - var searchQuery = this.getSearchQuery() - var results = await this.$axios.$get(`/api/search/covers?${searchQuery}`).catch((error) => { - console.error('Failed', error) - return [] - }) + const searchQuery = this.getSearchQuery() + const results = await this.$axios + .$get(`/api/search/covers?${searchQuery}`) + .then((res) => res.results) + .catch((error) => { + console.error('Failed', error) + return [] + }) this.coversFound = results this.isProcessing = false this.hasSearched = true diff --git a/client/components/modals/item/tabs/Match.vue b/client/components/modals/item/tabs/Match.vue index 7af136bd..79e0fe11 100644 --- a/client/components/modals/item/tabs/Match.vue +++ b/client/components/modals/item/tabs/Match.vue @@ -306,13 +306,13 @@ export default { this.runSearch() }, async runSearch() { - var searchQuery = this.getSearchQuery() + const searchQuery = this.getSearchQuery() if (this.lastSearch === searchQuery) return this.searchResults = [] this.isProcessing = true this.lastSearch = searchQuery - var searchEntity = this.isPodcast ? 'podcast' : 'books' - var results = await this.$axios.$get(`/api/search/${searchEntity}?${searchQuery}`, { timeout: 20000 }).catch((error) => { + const searchEntity = this.isPodcast ? 'podcast' : 'books' + let results = await this.$axios.$get(`/api/search/${searchEntity}?${searchQuery}`, { timeout: 20000 }).catch((error) => { console.error('Failed', error) return [] }) diff --git a/server/controllers/SearchController.js b/server/controllers/SearchController.js index fa61b52d..5ca217b3 100644 --- a/server/controllers/SearchController.js +++ b/server/controllers/SearchController.js @@ -4,16 +4,15 @@ class SearchController { constructor() { } async findBooks(req, res) { - var provider = req.query.provider || 'google' - var title = req.query.title || '' - var author = req.query.author || '' - res.json({ - results: await this.bookFinder.search(provider, title, author) - }) + const provider = req.query.provider || 'google' + const title = req.query.title || '' + const author = req.query.author || '' + const results = await this.bookFinder.search(provider, title, author) + res.json(results) } async findCovers(req, res) { - var query = req.query + const query = req.query const podcast = query.podcast == 1 if (!query.title) { @@ -21,31 +20,30 @@ class SearchController { return res.sendStatus(400) } - var result = null - if (podcast) result = await this.podcastFinder.findCovers(query.title) - else result = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null) + let results = null + if (podcast) results = await this.podcastFinder.findCovers(query.title) + else results = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null) res.json({ - results: result + results }) } async findPodcasts(req, res) { - var term = req.query.term - res.json({ - results: await this.podcastFinder.search(term) - }) + const term = req.query.term + const results = await this.podcastFinder.search(term) + res.json(results) } async findAuthor(req, res) { - var query = req.query.q - var author = await this.authorFinder.findAuthorByName(query) + const query = req.query.q + const author = await this.authorFinder.findAuthorByName(query) res.json(author) } async findChapters(req, res) { - var asin = req.query.asin - var region = (req.query.region || 'us').toLowerCase() - var chapterData = await this.bookFinder.findChapters(asin, region) + const asin = req.query.asin + const region = (req.query.region || 'us').toLowerCase() + const chapterData = await this.bookFinder.findChapters(asin, region) if (!chapterData) { return res.json({ error: 'Chapters not found' }) }