mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-11 01:17:50 +02:00
Update:findEpisode API endpoint validate title search param is a string
This commit is contained in:
parent
a018374d26
commit
c2897f819d
@ -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,20 +36,24 @@ 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 =
|
||||||
where: {
|
(await Database.libraryItemModel.count({
|
||||||
path: podcastPath
|
where: {
|
||||||
}
|
path: podcastPath
|
||||||
})) > 0
|
}
|
||||||
|
})) > 0
|
||||||
if (existingLibraryItem) {
|
if (existingLibraryItem) {
|
||||||
Logger.error(`[PodcastController] Podcast already exists at path "${podcastPath}"`)
|
Logger.error(`[PodcastController] Podcast already exists at path "${podcastPath}"`)
|
||||||
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
|
||||||
Logger.error(`[PodcastController] Failed to ensure podcast dir "${podcastPath}"`, error)
|
.ensureDir(podcastPath)
|
||||||
return false
|
.then(() => true)
|
||||||
})
|
.catch((error) => {
|
||||||
|
Logger.error(`[PodcastController] Failed to ensure podcast dir "${podcastPath}"`, error)
|
||||||
|
return false
|
||||||
|
})
|
||||||
if (!success) return res.status(400).send('Invalid podcast path')
|
if (!success) return res.status(400).send('Invalid podcast path')
|
||||||
|
|
||||||
const libraryItemFolderStats = await getFileTimestampsWithIno(podcastPath)
|
const libraryItemFolderStats = await getFileTimestampsWithIno(podcastPath)
|
||||||
@ -105,12 +108,12 @@ class PodcastController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* POST: /api/podcasts/feed
|
* POST: /api/podcasts/feed
|
||||||
*
|
*
|
||||||
* @typedef getPodcastFeedReqBody
|
* @typedef getPodcastFeedReqBody
|
||||||
* @property {string} rssFeed
|
* @property {string} rssFeed
|
||||||
*
|
*
|
||||||
* @param {import('express').Request<{}, {}, getPodcastFeedReqBody, {}} req
|
* @param {import('express').Request<{}, {}, getPodcastFeedReqBody, {}} req
|
||||||
* @param {import('express').Response} res
|
* @param {import('express').Response} res
|
||||||
*/
|
*/
|
||||||
async getPodcastFeed(req, res) {
|
async getPodcastFeed(req, res) {
|
||||||
if (!req.user.isAdminOrUp) {
|
if (!req.user.isAdminOrUp) {
|
||||||
@ -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,11 +281,14 @@ 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
|
||||||
Logger.info(`[PodcastController] Hard deleted episode file at "${audioFile.metadata.path}"`)
|
.remove(audioFile.metadata.path)
|
||||||
}).catch((error) => {
|
.then(() => {
|
||||||
Logger.error(`[PodcastController] Failed to hard delete episode file at "${audioFile.metadata.path}"`, error)
|
Logger.info(`[PodcastController] Hard deleted episode file at "${audioFile.metadata.path}"`)
|
||||||
})
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Logger.error(`[PodcastController] Failed to hard delete episode file at "${audioFile.metadata.path}"`, error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove episode from Podcast and library file
|
// Remove episode from Podcast and library file
|
||||||
|
Loading…
Reference in New Issue
Block a user