From 70d887bada02dc6f32802335fac23015fd95c2a5 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 20 Nov 2022 16:12:30 -0600 Subject: [PATCH] Update:API status codes and default provider for findCovers route --- server/controllers/PodcastController.js | 10 +++++----- server/controllers/SearchController.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js index 36c82d01..5c0b5e1e 100644 --- a/server/controllers/PodcastController.js +++ b/server/controllers/PodcastController.js @@ -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) diff --git a/server/controllers/SearchController.js b/server/controllers/SearchController.js index 9246bed9..05f0cff6 100644 --- a/server/controllers/SearchController.js +++ b/server/controllers/SearchController.js @@ -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) }