mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Fix refresh feed when book is deleted and belonged to a series/collection
This commit is contained in:
parent
5201625d38
commit
e7f7d1a573
@ -122,7 +122,7 @@ class RssFeedManager {
|
|||||||
attributes: ['id', 'updatedAt'],
|
attributes: ['id', 'updatedAt'],
|
||||||
include: {
|
include: {
|
||||||
model: Database.bookModel,
|
model: Database.bookModel,
|
||||||
attributes: ['id', 'updatedAt'],
|
attributes: ['id', 'audioFiles', 'updatedAt'],
|
||||||
through: {
|
through: {
|
||||||
attributes: []
|
attributes: []
|
||||||
},
|
},
|
||||||
@ -133,14 +133,16 @@ class RssFeedManager {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const totalBookTracks = feed.entity.books.reduce((total, book) => total + book.includedAudioFiles.length, 0)
|
||||||
|
if (feed.feedEpisodes.length !== totalBookTracks) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
let newEntityUpdatedAt = feed.entity.updatedAt
|
let newEntityUpdatedAt = feed.entity.updatedAt
|
||||||
|
|
||||||
const mostRecentItemUpdatedAt = feed.entity.books.reduce((mostRecent, book) => {
|
const mostRecentItemUpdatedAt = feed.entity.books.reduce((mostRecent, book) => {
|
||||||
let updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt
|
let updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt
|
||||||
if (updatedAt > mostRecent) {
|
return updatedAt > mostRecent ? updatedAt : mostRecent
|
||||||
return updatedAt
|
|
||||||
}
|
|
||||||
return mostRecent
|
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
if (mostRecentItemUpdatedAt > newEntityUpdatedAt) {
|
if (mostRecentItemUpdatedAt > newEntityUpdatedAt) {
|
||||||
@ -163,6 +165,9 @@ class RssFeedManager {
|
|||||||
let feed = await Database.feedModel.findOne({
|
let feed = await Database.feedModel.findOne({
|
||||||
where: {
|
where: {
|
||||||
slug: req.params.slug
|
slug: req.params.slug
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
model: Database.feedEpisodeModel
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!feed) {
|
if (!feed) {
|
||||||
@ -175,8 +180,6 @@ class RssFeedManager {
|
|||||||
if (feedRequiresUpdate) {
|
if (feedRequiresUpdate) {
|
||||||
Logger.info(`[RssFeedManager] Feed "${feed.title}" requires update - updating feed`)
|
Logger.info(`[RssFeedManager] Feed "${feed.title}" requires update - updating feed`)
|
||||||
feed = await feed.updateFeedForEntity()
|
feed = await feed.updateFeedForEntity()
|
||||||
} else {
|
|
||||||
feed.feedEpisodes = await feed.getFeedEpisodes()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const xml = feed.buildXml(req.originalHostPrefix)
|
const xml = feed.buildXml(req.originalHostPrefix)
|
||||||
|
@ -190,7 +190,8 @@ class Feed extends Model {
|
|||||||
const booksWithTracks = collectionExpanded.books.filter((book) => book.includedAudioFiles.length)
|
const booksWithTracks = collectionExpanded.books.filter((book) => book.includedAudioFiles.length)
|
||||||
|
|
||||||
const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
|
const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
|
||||||
return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent
|
const updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt
|
||||||
|
return updatedAt > mostRecent ? updatedAt : mostRecent
|
||||||
}, collectionExpanded.updatedAt)
|
}, collectionExpanded.updatedAt)
|
||||||
|
|
||||||
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
|
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
|
||||||
@ -278,7 +279,8 @@ class Feed extends Model {
|
|||||||
static getFeedObjForSeries(userId, seriesExpanded, slug, serverAddress, feedOptions = null) {
|
static getFeedObjForSeries(userId, seriesExpanded, slug, serverAddress, feedOptions = null) {
|
||||||
const booksWithTracks = seriesExpanded.books.filter((book) => book.includedAudioFiles.length)
|
const booksWithTracks = seriesExpanded.books.filter((book) => book.includedAudioFiles.length)
|
||||||
const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
|
const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
|
||||||
return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent
|
const updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt
|
||||||
|
return updatedAt > mostRecent ? updatedAt : mostRecent
|
||||||
}, seriesExpanded.updatedAt)
|
}, seriesExpanded.updatedAt)
|
||||||
|
|
||||||
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
|
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
|
||||||
@ -475,8 +477,6 @@ class Feed extends Model {
|
|||||||
/** @type {typeof import('./FeedEpisode')} */
|
/** @type {typeof import('./FeedEpisode')} */
|
||||||
const feedEpisodeModel = this.sequelize.models.feedEpisode
|
const feedEpisodeModel = this.sequelize.models.feedEpisode
|
||||||
|
|
||||||
this.feedEpisodes = await this.getFeedEpisodes()
|
|
||||||
|
|
||||||
let feedObj = null
|
let feedObj = null
|
||||||
let feedEpisodeCreateFunc = null
|
let feedEpisodeCreateFunc = null
|
||||||
let feedEpisodeCreateFuncEntity = null
|
let feedEpisodeCreateFuncEntity = null
|
||||||
|
Loading…
Reference in New Issue
Block a user