mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 01:09:26 +02:00
Migration change metadata folder from /books to /items, podcast data model updates, add podcast routes
This commit is contained in:
parent
43bbfbfee3
commit
f8d0384155
11 changed files with 153 additions and 89 deletions
62
server/controllers/PodcastController.js
Normal file
62
server/controllers/PodcastController.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
const axios = require('axios')
|
||||
const fs = require('fs-extra')
|
||||
const Logger = require('../Logger')
|
||||
const { parsePodcastRssFeedXml } = require('../utils/podcastUtils')
|
||||
const LibraryItem = require('../objects/LibraryItem')
|
||||
|
||||
class PodcastController {
|
||||
|
||||
async create(req, res) {
|
||||
if (!req.user.isRoot) {
|
||||
Logger.error(`[PodcastController] Non-root user attempted to create podcast`, req.user)
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
const payload = req.body
|
||||
|
||||
if (await fs.pathExists(payload.path)) {
|
||||
Logger.error(`[PodcastController] Attempt to create podcast when folder path already exists "${payload.path}"`)
|
||||
return res.status(400).send('Path already exists')
|
||||
}
|
||||
|
||||
var success = await fs.ensureDir(payload.path).then(() => true).catch((error) => {
|
||||
Logger.error(`[PodcastController] Failed to ensure podcast dir "${payload.path}"`, error)
|
||||
return false
|
||||
})
|
||||
if (!success) return res.status(400).send('Invalid podcast path')
|
||||
|
||||
if (payload.mediaMetadata.imageUrl) {
|
||||
// TODO: Download image
|
||||
}
|
||||
|
||||
var libraryItem = new LibraryItem()
|
||||
libraryItem.setData('podcast', payload)
|
||||
|
||||
await this.db.insertLibraryItem(libraryItem)
|
||||
this.emitter('item_added', libraryItem.toJSONExpanded())
|
||||
|
||||
res.json(libraryItem.toJSONExpanded())
|
||||
}
|
||||
|
||||
getPodcastFeed(req, res) {
|
||||
var url = req.body.rssFeed
|
||||
if (!url) {
|
||||
return res.status(400).send('Bad request')
|
||||
}
|
||||
|
||||
axios.get(url).then(async (data) => {
|
||||
if (!data || !data.data) {
|
||||
Logger.error('Invalid podcast feed request response')
|
||||
return res.status(500).send('Bad response from feed request')
|
||||
}
|
||||
var podcast = await parsePodcastRssFeedXml(data.data)
|
||||
if (!podcast) {
|
||||
return res.status(500).send('Invalid podcast RSS feed')
|
||||
}
|
||||
res.json(podcast)
|
||||
}).catch((error) => {
|
||||
console.error('Failed', error)
|
||||
res.status(500).send(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
module.exports = new PodcastController()
|
Loading…
Add table
Add a link
Reference in a new issue