mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
RSS feed for collection to update when any item in the collection is updated #606
This commit is contained in:
parent
9e4bc582cb
commit
315c83e4c3
@ -52,7 +52,7 @@ class LibraryItemController {
|
|||||||
await this.cacheManager.purgeCoverCache(libraryItem.id)
|
await this.cacheManager.purgeCoverCache(libraryItem.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasUpdates = libraryItem.update(req.body)
|
const hasUpdates = libraryItem.update(req.body)
|
||||||
if (hasUpdates) {
|
if (hasUpdates) {
|
||||||
Logger.debug(`[LibraryItemController] Updated now saving`)
|
Logger.debug(`[LibraryItemController] Updated now saving`)
|
||||||
await this.db.updateLibraryItem(libraryItem)
|
await this.db.updateLibraryItem(libraryItem)
|
||||||
@ -70,8 +70,8 @@ class LibraryItemController {
|
|||||||
// PATCH: will create new authors & series if in payload
|
// PATCH: will create new authors & series if in payload
|
||||||
//
|
//
|
||||||
async updateMedia(req, res) {
|
async updateMedia(req, res) {
|
||||||
var libraryItem = req.libraryItem
|
const libraryItem = req.libraryItem
|
||||||
var mediaPayload = req.body
|
const mediaPayload = req.body
|
||||||
// Item has cover and update is removing cover so purge it from cache
|
// Item has cover and update is removing cover so purge it from cache
|
||||||
if (libraryItem.media.coverPath && (mediaPayload.coverPath === '' || mediaPayload.coverPath === null)) {
|
if (libraryItem.media.coverPath && (mediaPayload.coverPath === '' || mediaPayload.coverPath === null)) {
|
||||||
await this.cacheManager.purgeCoverCache(libraryItem.id)
|
await this.cacheManager.purgeCoverCache(libraryItem.id)
|
||||||
@ -83,7 +83,7 @@ class LibraryItemController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Podcast specific
|
// Podcast specific
|
||||||
var isPodcastAutoDownloadUpdated = false
|
let isPodcastAutoDownloadUpdated = false
|
||||||
if (libraryItem.isPodcast) {
|
if (libraryItem.isPodcast) {
|
||||||
if (mediaPayload.autoDownloadEpisodes !== undefined && libraryItem.media.autoDownloadEpisodes !== mediaPayload.autoDownloadEpisodes) {
|
if (mediaPayload.autoDownloadEpisodes !== undefined && libraryItem.media.autoDownloadEpisodes !== mediaPayload.autoDownloadEpisodes) {
|
||||||
isPodcastAutoDownloadUpdated = true
|
isPodcastAutoDownloadUpdated = true
|
||||||
@ -92,8 +92,10 @@ class LibraryItemController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasUpdates = libraryItem.media.update(mediaPayload)
|
const hasUpdates = libraryItem.media.update(mediaPayload)
|
||||||
if (hasUpdates) {
|
if (hasUpdates) {
|
||||||
|
libraryItem.updatedAt = Date.now()
|
||||||
|
|
||||||
if (isPodcastAutoDownloadUpdated) {
|
if (isPodcastAutoDownloadUpdated) {
|
||||||
this.cronManager.checkUpdatePodcastCron(libraryItem)
|
this.cronManager.checkUpdatePodcastCron(libraryItem)
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,19 @@ class RssFeedManager {
|
|||||||
await this.db.updateEntity('feed', feed)
|
await this.db.updateEntity('feed', feed)
|
||||||
}
|
}
|
||||||
} else if (feed.entityType === 'collection') {
|
} else if (feed.entityType === 'collection') {
|
||||||
// TODO: Also trigger an update if any item in the collection was updated
|
|
||||||
const collection = this.db.collections.find(c => c.id === feed.entityId)
|
const collection = this.db.collections.find(c => c.id === feed.entityId)
|
||||||
if (collection) {
|
if (collection) {
|
||||||
const collectionExpanded = collection.toJSONExpanded(this.db.libraryItems)
|
const collectionExpanded = collection.toJSONExpanded(this.db.libraryItems)
|
||||||
if (!feed.entityUpdatedAt || collection.lastUpdate > feed.entityUpdatedAt) {
|
|
||||||
|
// Find most recently updated item in collection
|
||||||
|
let mostRecentlyUpdatedAt = collectionExpanded.lastUpdate
|
||||||
|
collectionExpanded.books.forEach((libraryItem) => {
|
||||||
|
if (libraryItem.media.tracks.length && libraryItem.updatedAt > mostRecentlyUpdatedAt) {
|
||||||
|
mostRecentlyUpdatedAt = libraryItem.updatedAt
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!feed.entityUpdatedAt || mostRecentlyUpdatedAt > feed.entityUpdatedAt) {
|
||||||
Logger.debug(`[RssFeedManager] Updating RSS feed for collection "${collection.name}"`)
|
Logger.debug(`[RssFeedManager] Updating RSS feed for collection "${collection.name}"`)
|
||||||
|
|
||||||
feed.updateFromCollection(collectionExpanded)
|
feed.updateFromCollection(collectionExpanded)
|
||||||
|
@ -167,7 +167,7 @@ class Feed {
|
|||||||
this.userId = userId
|
this.userId = userId
|
||||||
this.entityType = 'collection'
|
this.entityType = 'collection'
|
||||||
this.entityId = collectionExpanded.id
|
this.entityId = collectionExpanded.id
|
||||||
this.entityUpdatedAt = collectionExpanded.lastUpdate
|
this.entityUpdatedAt = collectionExpanded.lastUpdate // This will be set to the most recently updated library item
|
||||||
this.coverPath = firstItemWithCover?.coverPath || null
|
this.coverPath = firstItemWithCover?.coverPath || null
|
||||||
this.serverAddress = serverAddress
|
this.serverAddress = serverAddress
|
||||||
this.feedUrl = feedUrl
|
this.feedUrl = feedUrl
|
||||||
@ -184,6 +184,8 @@ class Feed {
|
|||||||
this.episodes = []
|
this.episodes = []
|
||||||
|
|
||||||
itemsWithTracks.forEach((item, index) => {
|
itemsWithTracks.forEach((item, index) => {
|
||||||
|
if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt
|
||||||
|
|
||||||
item.media.tracks.forEach((audioTrack) => {
|
item.media.tracks.forEach((audioTrack) => {
|
||||||
const feedEpisode = new FeedEpisode()
|
const feedEpisode = new FeedEpisode()
|
||||||
feedEpisode.setFromAudiobookTrack(item, serverAddress, slug, audioTrack, this.meta, index)
|
feedEpisode.setFromAudiobookTrack(item, serverAddress, slug, audioTrack, this.meta, index)
|
||||||
@ -211,6 +213,8 @@ class Feed {
|
|||||||
this.episodes = []
|
this.episodes = []
|
||||||
|
|
||||||
itemsWithTracks.forEach((item, index) => {
|
itemsWithTracks.forEach((item, index) => {
|
||||||
|
if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt
|
||||||
|
|
||||||
item.media.tracks.forEach((audioTrack) => {
|
item.media.tracks.forEach((audioTrack) => {
|
||||||
const feedEpisode = new FeedEpisode()
|
const feedEpisode = new FeedEpisode()
|
||||||
feedEpisode.setFromAudiobookTrack(item, this.serverAddress, this.slug, audioTrack, this.meta, index)
|
feedEpisode.setFromAudiobookTrack(item, this.serverAddress, this.slug, audioTrack, this.meta, index)
|
||||||
|
@ -136,11 +136,11 @@ class Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(payload) {
|
update(payload) {
|
||||||
var json = this.toJSON()
|
const json = this.toJSON()
|
||||||
delete json.audiobooks // do not update media entities here
|
delete json.audiobooks // do not update media entities here
|
||||||
delete json.ebooks
|
delete json.ebooks
|
||||||
|
|
||||||
var hasUpdates = false
|
let hasUpdates = false
|
||||||
for (const key in json) {
|
for (const key in json) {
|
||||||
if (payload[key] !== undefined) {
|
if (payload[key] !== undefined) {
|
||||||
if (key === 'metadata') {
|
if (key === 'metadata') {
|
||||||
|
Loading…
Reference in New Issue
Block a user