Update:API status codes and default provider for findCovers route

This commit is contained in:
advplyr 2022-11-20 16:12:30 -06:00
parent 357a63a4d9
commit 70d887bada
2 changed files with 14 additions and 7 deletions

View File

@ -11,20 +11,20 @@ class PodcastController {
async create(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user attempted to create podcast`, req.user)
return res.sendStatus(500)
return res.sendStatus(403)
}
const payload = req.body
const library = this.db.libraries.find(lib => lib.id === payload.libraryId)
if (!library) {
Logger.error(`[PodcastController] Create: Library not found "${payload.libraryId}"`)
return res.status(400).send('Library not found')
return res.status(404).send('Library not found')
}
const folder = library.folders.find(fold => fold.id === payload.folderId)
if (!folder) {
Logger.error(`[PodcastController] Create: Folder not found "${payload.folderId}"`)
return res.status(400).send('Folder not found')
return res.status(404).send('Folder not found')
}
var podcastPath = payload.path.replace(/\\/g, '/')
@ -115,7 +115,7 @@ class PodcastController {
async checkNewEpisodes(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user attempted to check/download episodes`, req.user)
return res.sendStatus(500)
return res.sendStatus(403)
}
var libraryItem = req.libraryItem
@ -135,7 +135,7 @@ class PodcastController {
clearEpisodeDownloadQueue(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user attempting to clear download queue "${req.user.username}"`)
return res.sendStatus(500)
return res.sendStatus(403)
}
this.podcastManager.clearDownloadQueue(req.params.id)
res.sendStatus(200)

View File

@ -1,3 +1,5 @@
const Logger = require("../Logger")
class SearchController {
constructor() { }
@ -11,11 +13,16 @@ class SearchController {
async findCovers(req, res) {
var query = req.query
var podcast = query.podcast == 1
const podcast = query.podcast == 1
if (!query.title) {
Logger.error(`[SearchController] findCovers: No title sent in query`)
return res.sendStatus(400)
}
var result = null
if (podcast) result = await this.podcastFinder.findCovers(query.title)
else result = await this.bookFinder.findCovers(query.provider, query.title, query.author || null)
else result = await this.bookFinder.findCovers(query.provider || 'google', query.title, query.author || null)
res.json(result)
}