2022-11-20 23:12:30 +01:00
|
|
|
const Logger = require("../Logger")
|
|
|
|
|
2022-11-19 20:28:06 +01:00
|
|
|
class SearchController {
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
async findBooks(req, res) {
|
|
|
|
var provider = req.query.provider || 'google'
|
|
|
|
var title = req.query.title || ''
|
|
|
|
var author = req.query.author || ''
|
2022-11-29 19:23:02 +01:00
|
|
|
res.json({
|
|
|
|
results: await this.bookFinder.search(provider, title, author)
|
|
|
|
})
|
2022-11-19 20:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async findCovers(req, res) {
|
|
|
|
var query = req.query
|
2022-11-20 23:12:30 +01:00
|
|
|
const podcast = query.podcast == 1
|
|
|
|
|
|
|
|
if (!query.title) {
|
|
|
|
Logger.error(`[SearchController] findCovers: No title sent in query`)
|
|
|
|
return res.sendStatus(400)
|
|
|
|
}
|
2022-11-19 20:28:06 +01:00
|
|
|
|
|
|
|
var result = null
|
|
|
|
if (podcast) result = await this.podcastFinder.findCovers(query.title)
|
2022-11-20 23:12:30 +01:00
|
|
|
else result = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null)
|
2022-11-29 19:23:02 +01:00
|
|
|
res.json({
|
|
|
|
results: result
|
|
|
|
})
|
2022-11-19 20:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async findPodcasts(req, res) {
|
|
|
|
var term = req.query.term
|
2022-11-29 19:23:02 +01:00
|
|
|
res.json({
|
|
|
|
results: await this.podcastFinder.search(term)
|
|
|
|
})
|
2022-11-19 20:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async findAuthor(req, res) {
|
|
|
|
var query = req.query.q
|
|
|
|
var 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)
|
|
|
|
if (!chapterData) {
|
|
|
|
return res.json({ error: 'Chapters not found' })
|
|
|
|
}
|
|
|
|
res.json(chapterData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = new SearchController()
|