mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-11 08:18:17 +02:00
Update OPML api route to load podcasts from db
This commit is contained in:
parent
8d451217a3
commit
ff0d6326d3
@ -1047,8 +1047,28 @@ class LibraryController {
|
|||||||
res.json(payload)
|
res.json(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
getOPMLFile(req, res) {
|
/**
|
||||||
const opmlText = this.podcastManager.generateOPMLFileText(req.libraryItems)
|
* GET: /api/libraries/:id/opml
|
||||||
|
* Get OPML file for a podcast library
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
|
async getOPMLFile(req, res) {
|
||||||
|
const userPermissionPodcastWhere = libraryItemsPodcastFilters.getUserPermissionPodcastWhereQuery(req.user)
|
||||||
|
const podcasts = await Database.podcastModel.findAll({
|
||||||
|
attributes: ['id', 'feedURL', 'title', 'description', 'itunesPageURL', 'language'],
|
||||||
|
where: userPermissionPodcastWhere.podcastWhere,
|
||||||
|
replacements: userPermissionPodcastWhere.replacements,
|
||||||
|
include: {
|
||||||
|
model: Database.libraryItemModel,
|
||||||
|
attributes: ['id', 'libraryId'],
|
||||||
|
where: {
|
||||||
|
libraryId: req.library.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const opmlText = this.podcastManager.generateOPMLFileText(podcasts)
|
||||||
res.type('application/xml')
|
res.type('application/xml')
|
||||||
res.send(opmlText)
|
res.send(opmlText)
|
||||||
}
|
}
|
||||||
|
@ -372,8 +372,13 @@ class PodcastManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateOPMLFileText(libraryItems) {
|
/**
|
||||||
return opmlGenerator.generate(libraryItems)
|
* OPML file string for podcasts in a library
|
||||||
|
* @param {import('../models/Podcast')[]} podcasts
|
||||||
|
* @returns {string} XML string
|
||||||
|
*/
|
||||||
|
generateOPMLFileText(podcasts) {
|
||||||
|
return opmlGenerator.generate(podcasts)
|
||||||
}
|
}
|
||||||
|
|
||||||
getDownloadQueueDetails(libraryId = null) {
|
getDownloadQueueDetails(libraryId = null) {
|
||||||
|
@ -95,7 +95,7 @@ class ApiRouter {
|
|||||||
this.router.get('/libraries/:id/matchall', LibraryController.middlewareNew.bind(this), LibraryController.matchAll.bind(this))
|
this.router.get('/libraries/:id/matchall', LibraryController.middlewareNew.bind(this), LibraryController.matchAll.bind(this))
|
||||||
this.router.post('/libraries/:id/scan', LibraryController.middlewareNew.bind(this), LibraryController.scan.bind(this))
|
this.router.post('/libraries/:id/scan', LibraryController.middlewareNew.bind(this), LibraryController.scan.bind(this))
|
||||||
this.router.get('/libraries/:id/recent-episodes', LibraryController.middlewareNew.bind(this), LibraryController.getRecentEpisodes.bind(this))
|
this.router.get('/libraries/:id/recent-episodes', LibraryController.middlewareNew.bind(this), LibraryController.getRecentEpisodes.bind(this))
|
||||||
this.router.get('/libraries/:id/opml', LibraryController.middleware.bind(this), LibraryController.getOPMLFile.bind(this))
|
this.router.get('/libraries/:id/opml', LibraryController.middlewareNew.bind(this), LibraryController.getOPMLFile.bind(this))
|
||||||
this.router.post('/libraries/order', LibraryController.reorder.bind(this))
|
this.router.post('/libraries/order', LibraryController.reorder.bind(this))
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1,23 +1,29 @@
|
|||||||
const xml = require('../../libs/xml')
|
const xml = require('../../libs/xml')
|
||||||
|
|
||||||
module.exports.generate = (libraryItems, indent = true) => {
|
/**
|
||||||
|
* Generate OPML file string for podcasts in a library
|
||||||
|
* @param {import('../../models/Podcast')[]} podcasts
|
||||||
|
* @param {boolean} [indent=true]
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
module.exports.generate = (podcasts, indent = true) => {
|
||||||
const bodyItems = []
|
const bodyItems = []
|
||||||
libraryItems.forEach((item) => {
|
podcasts.forEach((podcast) => {
|
||||||
if (!item.media.metadata.feedUrl) return
|
if (!podcast.feedURL) return
|
||||||
const feedAttributes = {
|
const feedAttributes = {
|
||||||
type: 'rss',
|
type: 'rss',
|
||||||
text: item.media.metadata.title,
|
text: podcast.title,
|
||||||
title: item.media.metadata.title,
|
title: podcast.title,
|
||||||
xmlUrl: item.media.metadata.feedUrl
|
xmlUrl: podcast.feedURL
|
||||||
}
|
}
|
||||||
if (item.media.metadata.description) {
|
if (podcast.description) {
|
||||||
feedAttributes.description = item.media.metadata.description
|
feedAttributes.description = podcast.description
|
||||||
}
|
}
|
||||||
if (item.media.metadata.itunesPageUrl) {
|
if (podcast.itunesPageUrl) {
|
||||||
feedAttributes.htmlUrl = item.media.metadata.itunesPageUrl
|
feedAttributes.htmlUrl = podcast.itunesPageUrl
|
||||||
}
|
}
|
||||||
if (item.media.metadata.language) {
|
if (podcast.language) {
|
||||||
feedAttributes.language = item.media.metadata.language
|
feedAttributes.language = podcast.language
|
||||||
}
|
}
|
||||||
bodyItems.push({
|
bodyItems.push({
|
||||||
outline: {
|
outline: {
|
||||||
|
Loading…
Reference in New Issue
Block a user