mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-28 17:49:06 +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)
|
||||
}
|
||||
|
||||
var hasUpdates = libraryItem.update(req.body)
|
||||
const hasUpdates = libraryItem.update(req.body)
|
||||
if (hasUpdates) {
|
||||
Logger.debug(`[LibraryItemController] Updated now saving`)
|
||||
await this.db.updateLibraryItem(libraryItem)
|
||||
@ -70,8 +70,8 @@ class LibraryItemController {
|
||||
// PATCH: will create new authors & series if in payload
|
||||
//
|
||||
async updateMedia(req, res) {
|
||||
var libraryItem = req.libraryItem
|
||||
var mediaPayload = req.body
|
||||
const libraryItem = req.libraryItem
|
||||
const mediaPayload = req.body
|
||||
// Item has cover and update is removing cover so purge it from cache
|
||||
if (libraryItem.media.coverPath && (mediaPayload.coverPath === '' || mediaPayload.coverPath === null)) {
|
||||
await this.cacheManager.purgeCoverCache(libraryItem.id)
|
||||
@ -83,7 +83,7 @@ class LibraryItemController {
|
||||
}
|
||||
|
||||
// Podcast specific
|
||||
var isPodcastAutoDownloadUpdated = false
|
||||
let isPodcastAutoDownloadUpdated = false
|
||||
if (libraryItem.isPodcast) {
|
||||
if (mediaPayload.autoDownloadEpisodes !== undefined && libraryItem.media.autoDownloadEpisodes !== mediaPayload.autoDownloadEpisodes) {
|
||||
isPodcastAutoDownloadUpdated = true
|
||||
@ -92,8 +92,10 @@ class LibraryItemController {
|
||||
}
|
||||
}
|
||||
|
||||
var hasUpdates = libraryItem.media.update(mediaPayload)
|
||||
const hasUpdates = libraryItem.media.update(mediaPayload)
|
||||
if (hasUpdates) {
|
||||
libraryItem.updatedAt = Date.now()
|
||||
|
||||
if (isPodcastAutoDownloadUpdated) {
|
||||
this.cronManager.checkUpdatePodcastCron(libraryItem)
|
||||
}
|
||||
|
@ -52,11 +52,19 @@ class RssFeedManager {
|
||||
await this.db.updateEntity('feed', feed)
|
||||
}
|
||||
} 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)
|
||||
if (collection) {
|
||||
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}"`)
|
||||
|
||||
feed.updateFromCollection(collectionExpanded)
|
||||
|
@ -167,7 +167,7 @@ class Feed {
|
||||
this.userId = userId
|
||||
this.entityType = 'collection'
|
||||
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.serverAddress = serverAddress
|
||||
this.feedUrl = feedUrl
|
||||
@ -184,6 +184,8 @@ class Feed {
|
||||
this.episodes = []
|
||||
|
||||
itemsWithTracks.forEach((item, index) => {
|
||||
if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt
|
||||
|
||||
item.media.tracks.forEach((audioTrack) => {
|
||||
const feedEpisode = new FeedEpisode()
|
||||
feedEpisode.setFromAudiobookTrack(item, serverAddress, slug, audioTrack, this.meta, index)
|
||||
@ -211,6 +213,8 @@ class Feed {
|
||||
this.episodes = []
|
||||
|
||||
itemsWithTracks.forEach((item, index) => {
|
||||
if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt
|
||||
|
||||
item.media.tracks.forEach((audioTrack) => {
|
||||
const feedEpisode = new FeedEpisode()
|
||||
feedEpisode.setFromAudiobookTrack(item, this.serverAddress, this.slug, audioTrack, this.meta, index)
|
||||
|
@ -136,11 +136,11 @@ class Book {
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var json = this.toJSON()
|
||||
const json = this.toJSON()
|
||||
delete json.audiobooks // do not update media entities here
|
||||
delete json.ebooks
|
||||
|
||||
var hasUpdates = false
|
||||
let hasUpdates = false
|
||||
for (const key in json) {
|
||||
if (payload[key] !== undefined) {
|
||||
if (key === 'metadata') {
|
||||
|
Loading…
Reference in New Issue
Block a user