mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 11:21:36 +00:00
Merge 3cae110360 into d205c6f734
This commit is contained in:
commit
2f1596cdeb
30 changed files with 1163 additions and 35 deletions
|
|
@ -19,6 +19,7 @@ const Scanner = require('../scanner/Scanner')
|
|||
const Database = require('../Database')
|
||||
const Watcher = require('../Watcher')
|
||||
const RssFeedManager = require('../managers/RssFeedManager')
|
||||
const PodcastManager = require('../managers/PodcastManager')
|
||||
|
||||
const libraryFilters = require('../utils/queries/libraryFilters')
|
||||
const libraryItemsPodcastFilters = require('../utils/queries/libraryItemsPodcastFilters')
|
||||
|
|
@ -219,7 +220,7 @@ class LibraryController {
|
|||
* @param {Response} res
|
||||
*/
|
||||
async getEpisodeDownloadQueue(req, res) {
|
||||
const libraryDownloadQueueDetails = this.podcastManager.getDownloadQueueDetails(req.library.id)
|
||||
const libraryDownloadQueueDetails = PodcastManager.getDownloadQueueDetails(req.library.id)
|
||||
res.json(libraryDownloadQueueDetails)
|
||||
}
|
||||
|
||||
|
|
@ -1288,7 +1289,7 @@ class LibraryController {
|
|||
}
|
||||
})
|
||||
|
||||
const opmlText = this.podcastManager.generateOPMLFileText(podcasts)
|
||||
const opmlText = PodcastManager.generateOPMLFileText(podcasts)
|
||||
res.type('application/xml')
|
||||
res.send(opmlText)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ const RssFeedManager = require('../managers/RssFeedManager')
|
|||
const CacheManager = require('../managers/CacheManager')
|
||||
const CoverManager = require('../managers/CoverManager')
|
||||
const ShareManager = require('../managers/ShareManager')
|
||||
const PodcastManager = require('../managers/PodcastManager')
|
||||
|
||||
/**
|
||||
* @typedef RequestUserObject
|
||||
|
|
@ -69,10 +70,10 @@ class LibraryItemController {
|
|||
}
|
||||
|
||||
if (item.mediaType === 'podcast' && includeEntities.includes('downloads')) {
|
||||
const downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
|
||||
const downloadsInQueue = PodcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
|
||||
item.episodeDownloadsQueued = downloadsInQueue.map((d) => d.toJSONForClient())
|
||||
if (this.podcastManager.currentDownload?.libraryItemId === req.libraryItem.id) {
|
||||
item.episodesDownloading = [this.podcastManager.currentDownload.toJSONForClient()]
|
||||
if (PodcastManager.currentDownload?.libraryItemId === req.libraryItem.id) {
|
||||
item.episodesDownloading = [PodcastManager.currentDownload.toJSONForClient()]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
82
server/controllers/PluginController.js
Normal file
82
server/controllers/PluginController.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
const { Request, Response, NextFunction } = require('express')
|
||||
const PluginManager = require('../managers/PluginManager')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class PluginController {
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
getConfig(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
res.json({
|
||||
config: req.pluginData.instance.config
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST: /api/plugins/:id/action
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async handleAction(req, res) {
|
||||
const actionName = req.body.pluginAction
|
||||
const target = req.body.target
|
||||
const data = req.body.data
|
||||
Logger.info(`[PluginController] Handle plugin "${req.pluginData.manifest.name}" action ${actionName} ${target}`, data)
|
||||
const actionData = await PluginManager.onAction(req.pluginData, actionName, target, data)
|
||||
if (!actionData || actionData.error) {
|
||||
return res.status(400).send(actionData?.error || 'Error performing action')
|
||||
}
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
* POST: /api/plugins/:id/config
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async handleConfigSave(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
if (!req.body.config || typeof req.body.config !== 'object') {
|
||||
return res.status(400).send('Invalid config')
|
||||
}
|
||||
|
||||
const config = req.body.config
|
||||
Logger.info(`[PluginController] Handle save config for plugin ${req.pluginData.manifest.name}`, config)
|
||||
const saveData = await PluginManager.onConfigSave(req.pluginData, config)
|
||||
if (!saveData || saveData.error) {
|
||||
return res.status(400).send(saveData?.error || 'Error saving config')
|
||||
}
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async middleware(req, res, next) {
|
||||
if (req.params.id) {
|
||||
const pluginData = PluginManager.getPluginDataById(req.params.id)
|
||||
if (!pluginData) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
await pluginData.instance.reload()
|
||||
req.pluginData = pluginData
|
||||
}
|
||||
next()
|
||||
}
|
||||
}
|
||||
module.exports = new PluginController()
|
||||
|
|
@ -11,6 +11,7 @@ const { validateUrl } = require('../utils/index')
|
|||
|
||||
const Scanner = require('../scanner/Scanner')
|
||||
const CoverManager = require('../managers/CoverManager')
|
||||
const PodcastManager = require('../managers/PodcastManager')
|
||||
|
||||
const LibraryItem = require('../objects/LibraryItem')
|
||||
|
||||
|
|
@ -114,7 +115,7 @@ class PodcastController {
|
|||
|
||||
if (payload.episodesToDownload?.length) {
|
||||
Logger.info(`[PodcastController] Podcast created now starting ${payload.episodesToDownload.length} episode downloads`)
|
||||
this.podcastManager.downloadPodcastEpisodes(libraryItem, payload.episodesToDownload)
|
||||
PodcastManager.downloadPodcastEpisodes(libraryItem, payload.episodesToDownload)
|
||||
}
|
||||
|
||||
// Turn on podcast auto download cron if not already on
|
||||
|
|
@ -169,7 +170,7 @@ class PodcastController {
|
|||
}
|
||||
|
||||
res.json({
|
||||
feeds: this.podcastManager.getParsedOPMLFileFeeds(req.body.opmlText)
|
||||
feeds: PodcastManager.getParsedOPMLFileFeeds(req.body.opmlText)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +204,7 @@ class PodcastController {
|
|||
return res.status(404).send('Folder not found')
|
||||
}
|
||||
const autoDownloadEpisodes = !!req.body.autoDownloadEpisodes
|
||||
this.podcastManager.createPodcastsFromFeedUrls(rssFeeds, folder, autoDownloadEpisodes, this.cronManager)
|
||||
PodcastManager.createPodcastsFromFeedUrls(rssFeeds, folder, autoDownloadEpisodes, this.cronManager)
|
||||
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
|
@ -230,7 +231,7 @@ class PodcastController {
|
|||
|
||||
const maxEpisodesToDownload = !isNaN(req.query.limit) ? Number(req.query.limit) : 3
|
||||
|
||||
var newEpisodes = await this.podcastManager.checkAndDownloadNewEpisodes(libraryItem, maxEpisodesToDownload)
|
||||
var newEpisodes = await PodcastManager.checkAndDownloadNewEpisodes(libraryItem, maxEpisodesToDownload)
|
||||
res.json({
|
||||
episodes: newEpisodes || []
|
||||
})
|
||||
|
|
@ -239,8 +240,6 @@ class PodcastController {
|
|||
/**
|
||||
* GET: /api/podcasts/:id/clear-queue
|
||||
*
|
||||
* @this {import('../routers/ApiRouter')}
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
|
|
@ -249,22 +248,20 @@ class PodcastController {
|
|||
Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempting to clear download queue`)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
this.podcastManager.clearDownloadQueue(req.params.id)
|
||||
PodcastManager.clearDownloadQueue(req.params.id)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
* GET: /api/podcasts/:id/downloads
|
||||
*
|
||||
* @this {import('../routers/ApiRouter')}
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
getEpisodeDownloads(req, res) {
|
||||
var libraryItem = req.libraryItem
|
||||
|
||||
var downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(libraryItem.id)
|
||||
var downloadsInQueue = PodcastManager.getEpisodeDownloadsInQueue(libraryItem.id)
|
||||
res.json({
|
||||
downloads: downloadsInQueue.map((d) => d.toJSONForClient())
|
||||
})
|
||||
|
|
@ -290,8 +287,6 @@ class PodcastController {
|
|||
/**
|
||||
* POST: /api/podcasts/:id/download-episodes
|
||||
*
|
||||
* @this {import('../routers/ApiRouter')}
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
|
|
@ -306,7 +301,7 @@ class PodcastController {
|
|||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
this.podcastManager.downloadPodcastEpisodes(libraryItem, episodes)
|
||||
PodcastManager.downloadPodcastEpisodes(libraryItem, episodes)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue