Update get tags route and revert podcast/books search route

This commit is contained in:
advplyr 2022-12-12 17:45:51 -06:00
parent 0ae853c119
commit 2d9035d90b
4 changed files with 31 additions and 30 deletions

View File

@ -201,8 +201,8 @@ export default {
this.loadingTags = true this.loadingTags = true
this.$axios this.$axios
.$get(`/api/tags`) .$get(`/api/tags`)
.then((tags) => { .then((res) => {
this.tags = tags this.tags = res.tags
this.loadingTags = false this.loadingTags = false
}) })
.catch((error) => { .catch((error) => {

View File

@ -303,8 +303,11 @@ export default {
this.persistProvider() this.persistProvider()
this.isProcessing = true this.isProcessing = true
var searchQuery = this.getSearchQuery() const searchQuery = this.getSearchQuery()
var results = await this.$axios.$get(`/api/search/covers?${searchQuery}`).catch((error) => { const results = await this.$axios
.$get(`/api/search/covers?${searchQuery}`)
.then((res) => res.results)
.catch((error) => {
console.error('Failed', error) console.error('Failed', error)
return [] return []
}) })

View File

@ -306,13 +306,13 @@ export default {
this.runSearch() this.runSearch()
}, },
async runSearch() { async runSearch() {
var searchQuery = this.getSearchQuery() const searchQuery = this.getSearchQuery()
if (this.lastSearch === searchQuery) return if (this.lastSearch === searchQuery) return
this.searchResults = [] this.searchResults = []
this.isProcessing = true this.isProcessing = true
this.lastSearch = searchQuery this.lastSearch = searchQuery
var searchEntity = this.isPodcast ? 'podcast' : 'books' const searchEntity = this.isPodcast ? 'podcast' : 'books'
var results = await this.$axios.$get(`/api/search/${searchEntity}?${searchQuery}`, { timeout: 20000 }).catch((error) => { let results = await this.$axios.$get(`/api/search/${searchEntity}?${searchQuery}`, { timeout: 20000 }).catch((error) => {
console.error('Failed', error) console.error('Failed', error)
return [] return []
}) })

View File

@ -4,16 +4,15 @@ class SearchController {
constructor() { } constructor() { }
async findBooks(req, res) { async findBooks(req, res) {
var provider = req.query.provider || 'google' const provider = req.query.provider || 'google'
var title = req.query.title || '' const title = req.query.title || ''
var author = req.query.author || '' const author = req.query.author || ''
res.json({ const results = await this.bookFinder.search(provider, title, author)
results: await this.bookFinder.search(provider, title, author) res.json(results)
})
} }
async findCovers(req, res) { async findCovers(req, res) {
var query = req.query const query = req.query
const podcast = query.podcast == 1 const podcast = query.podcast == 1
if (!query.title) { if (!query.title) {
@ -21,31 +20,30 @@ class SearchController {
return res.sendStatus(400) return res.sendStatus(400)
} }
var result = null let results = null
if (podcast) result = await this.podcastFinder.findCovers(query.title) if (podcast) results = await this.podcastFinder.findCovers(query.title)
else result = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null) else results = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null)
res.json({ res.json({
results: result results
}) })
} }
async findPodcasts(req, res) { async findPodcasts(req, res) {
var term = req.query.term const term = req.query.term
res.json({ const results = await this.podcastFinder.search(term)
results: await this.podcastFinder.search(term) res.json(results)
})
} }
async findAuthor(req, res) { async findAuthor(req, res) {
var query = req.query.q const query = req.query.q
var author = await this.authorFinder.findAuthorByName(query) const author = await this.authorFinder.findAuthorByName(query)
res.json(author) res.json(author)
} }
async findChapters(req, res) { async findChapters(req, res) {
var asin = req.query.asin const asin = req.query.asin
var region = (req.query.region || 'us').toLowerCase() const region = (req.query.region || 'us').toLowerCase()
var chapterData = await this.bookFinder.findChapters(asin, region) const chapterData = await this.bookFinder.findChapters(asin, region)
if (!chapterData) { if (!chapterData) {
return res.json({ error: 'Chapters not found' }) return res.json({ error: 'Chapters not found' })
} }