Add:API endpoint for opening RSS feed for collection #606 #1265

This commit is contained in:
advplyr 2022-12-26 17:48:39 -06:00
parent e803dcd325
commit 061695f922
6 changed files with 157 additions and 7 deletions

View file

@ -41,6 +41,40 @@ class RSSFeedController {
})
}
// POST: api/feeds/collection/:collectionId/open
async openRSSFeedForCollection(req, res) {
const options = req.body || {}
const collection = this.db.collections.find(li => li.id === req.params.collectionId)
if (!collection) return res.sendStatus(404)
// Check request body options exist
if (!options.serverAddress || !options.slug) {
Logger.error(`[RSSFeedController] Invalid request body to open RSS feed`)
return res.status(400).send('Invalid request body')
}
// Check that this slug is not being used for another feed (slug will also be the Feed id)
if (this.rssFeedManager.feeds[options.slug]) {
Logger.error(`[RSSFeedController] Cannot open RSS feed because slug "${options.slug}" is already in use`)
return res.status(400).send('Slug already in use')
}
const collectionExpanded = collection.toJSONExpanded(this.db.libraryItems)
const collectionItemsWithTracks = collectionExpanded.books.filter(li => li.media.tracks.length)
// Check collection has audio tracks
if (!collectionItemsWithTracks.length) {
Logger.error(`[RSSFeedController] Cannot open RSS feed for collection "${collection.name}" because it has no audio tracks`)
return res.status(400).send('Collection has no audio tracks')
}
const feed = await this.rssFeedManager.openFeedForCollection(req.user, collectionExpanded, req.body)
res.json({
feed: feed.toJSONMinified()
})
}
// POST: api/feeds/:id/close
async closeRSSFeed(req, res) {
await this.rssFeedManager.closeRssFeed(req.params.id)