1
0
mirror of https://github.com/advplyr/audiobookshelf.git synced 2025-04-26 00:08:17 +02:00

Update:findEpisode API endpoint validate title search param is a string

This commit is contained in:
advplyr 2024-06-09 13:55:53 -05:00
parent a018374d26
commit c2897f819d

View File

@ -14,7 +14,6 @@ const CoverManager = require('../managers/CoverManager')
const LibraryItem = require('../objects/LibraryItem') const LibraryItem = require('../objects/LibraryItem')
class PodcastController { class PodcastController {
async create(req, res) { async create(req, res) {
if (!req.user.isAdminOrUp) { if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempted to create podcast`) Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempted to create podcast`)
@ -28,7 +27,7 @@ class PodcastController {
return res.status(404).send('Library not found') return res.status(404).send('Library not found')
} }
const folder = library.folders.find(fold => fold.id === payload.folderId) const folder = library.folders.find((fold) => fold.id === payload.folderId)
if (!folder) { if (!folder) {
Logger.error(`[PodcastController] Create: Folder not found "${payload.folderId}"`) Logger.error(`[PodcastController] Create: Folder not found "${payload.folderId}"`)
return res.status(404).send('Folder not found') return res.status(404).send('Folder not found')
@ -37,7 +36,8 @@ class PodcastController {
const podcastPath = filePathToPOSIX(payload.path) const podcastPath = filePathToPOSIX(payload.path)
// Check if a library item with this podcast folder exists already // Check if a library item with this podcast folder exists already
const existingLibraryItem = (await Database.libraryItemModel.count({ const existingLibraryItem =
(await Database.libraryItemModel.count({
where: { where: {
path: podcastPath path: podcastPath
} }
@ -47,7 +47,10 @@ class PodcastController {
return res.status(400).send('Podcast already exists') return res.status(400).send('Podcast already exists')
} }
const success = await fs.ensureDir(podcastPath).then(() => true).catch((error) => { const success = await fs
.ensureDir(podcastPath)
.then(() => true)
.catch((error) => {
Logger.error(`[PodcastController] Failed to ensure podcast dir "${podcastPath}"`, error) Logger.error(`[PodcastController] Failed to ensure podcast dir "${podcastPath}"`, error)
return false return false
}) })
@ -178,7 +181,7 @@ class PodcastController {
var downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(libraryItem.id) var downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(libraryItem.id)
res.json({ res.json({
downloads: downloadsInQueue.map(d => d.toJSONForClient()) downloads: downloadsInQueue.map((d) => d.toJSONForClient())
}) })
} }
@ -189,8 +192,8 @@ class PodcastController {
return res.status(500).send('Podcast does not have an RSS feed URL') return res.status(500).send('Podcast does not have an RSS feed URL')
} }
var searchTitle = req.query.title const searchTitle = req.query.title
if (!searchTitle) { if (!searchTitle || typeof searchTitle !== 'string') {
return res.sendStatus(500) return res.sendStatus(500)
} }
const episodes = await findMatchingEpisodes(rssFeedUrl, searchTitle) const episodes = await findMatchingEpisodes(rssFeedUrl, searchTitle)
@ -254,7 +257,7 @@ class PodcastController {
const episodeId = req.params.episodeId const episodeId = req.params.episodeId
const libraryItem = req.libraryItem const libraryItem = req.libraryItem
const episode = libraryItem.media.episodes.find(ep => ep.id === episodeId) const episode = libraryItem.media.episodes.find((ep) => ep.id === episodeId)
if (!episode) { if (!episode) {
Logger.error(`[PodcastController] getEpisode episode ${episodeId} not found for item ${libraryItem.id}`) Logger.error(`[PodcastController] getEpisode episode ${episodeId} not found for item ${libraryItem.id}`)
return res.sendStatus(404) return res.sendStatus(404)
@ -269,7 +272,7 @@ class PodcastController {
const libraryItem = req.libraryItem const libraryItem = req.libraryItem
const hardDelete = req.query.hard === '1' const hardDelete = req.query.hard === '1'
const episode = libraryItem.media.episodes.find(ep => ep.id === episodeId) const episode = libraryItem.media.episodes.find((ep) => ep.id === episodeId)
if (!episode) { if (!episode) {
Logger.error(`[PodcastController] removeEpisode episode ${episodeId} not found for item ${libraryItem.id}`) Logger.error(`[PodcastController] removeEpisode episode ${episodeId} not found for item ${libraryItem.id}`)
return res.sendStatus(404) return res.sendStatus(404)
@ -278,9 +281,12 @@ class PodcastController {
if (hardDelete) { if (hardDelete) {
const audioFile = episode.audioFile const audioFile = episode.audioFile
// TODO: this will trigger the watcher. should maybe handle this gracefully // TODO: this will trigger the watcher. should maybe handle this gracefully
await fs.remove(audioFile.metadata.path).then(() => { await fs
.remove(audioFile.metadata.path)
.then(() => {
Logger.info(`[PodcastController] Hard deleted episode file at "${audioFile.metadata.path}"`) Logger.info(`[PodcastController] Hard deleted episode file at "${audioFile.metadata.path}"`)
}).catch((error) => { })
.catch((error) => {
Logger.error(`[PodcastController] Failed to hard delete episode file at "${audioFile.metadata.path}"`, error) Logger.error(`[PodcastController] Failed to hard delete episode file at "${audioFile.metadata.path}"`, error)
}) })
} }