Fix feed create entityUpdatedAt value

This commit is contained in:
advplyr 2024-12-15 14:07:46 -06:00
parent 837a180dc1
commit 369c05936b

View File

@ -279,11 +279,20 @@ class Feed extends Model {
static async createFeedForLibraryItem(userId, libraryItem, slug, serverAddress, feedOptions) { static async createFeedForLibraryItem(userId, libraryItem, slug, serverAddress, feedOptions) {
const media = libraryItem.media const media = libraryItem.media
let entityUpdatedAt = libraryItem.updatedAt
// Podcast feeds should use the most recent episode updatedAt if more recent
if (libraryItem.mediaType === 'podcast') {
entityUpdatedAt = libraryItem.media.podcastEpisodes.reduce((mostRecent, episode) => {
return episode.updatedAt > mostRecent ? episode.updatedAt : mostRecent
}, entityUpdatedAt)
}
const feedObj = { const feedObj = {
slug, slug,
entityType: 'libraryItem', entityType: 'libraryItem',
entityId: libraryItem.id, entityId: libraryItem.id,
entityUpdatedAt: libraryItem.updatedAt, entityUpdatedAt,
serverAddress, serverAddress,
feedURL: `/feed/${slug}`, feedURL: `/feed/${slug}`,
imageURL: media.coverPath ? `/feed/${slug}/cover${Path.extname(media.coverPath)}` : `/Logo.png`, imageURL: media.coverPath ? `/feed/${slug}/cover${Path.extname(media.coverPath)}` : `/Logo.png`,
@ -336,9 +345,10 @@ class Feed extends Model {
*/ */
static async createFeedForCollection(userId, collectionExpanded, slug, serverAddress, feedOptions) { static async createFeedForCollection(userId, collectionExpanded, slug, serverAddress, feedOptions) {
const booksWithTracks = collectionExpanded.books.filter((book) => book.includedAudioFiles.length) const booksWithTracks = collectionExpanded.books.filter((book) => book.includedAudioFiles.length)
const libraryItemMostRecentlyUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
return book.libraryItem.updatedAt > mostRecent.libraryItem.updatedAt ? book : mostRecent const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
}).libraryItem.updatedAt return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent
}, collectionExpanded.updatedAt)
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath) const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
@ -355,7 +365,7 @@ class Feed extends Model {
slug, slug,
entityType: 'collection', entityType: 'collection',
entityId: collectionExpanded.id, entityId: collectionExpanded.id,
entityUpdatedAt: libraryItemMostRecentlyUpdatedAt, entityUpdatedAt,
serverAddress, serverAddress,
feedURL: `/feed/${slug}`, feedURL: `/feed/${slug}`,
imageURL: firstBookWithCover?.coverPath ? `/feed/${slug}/cover${Path.extname(firstBookWithCover.coverPath)}` : `/Logo.png`, imageURL: firstBookWithCover?.coverPath ? `/feed/${slug}/cover${Path.extname(firstBookWithCover.coverPath)}` : `/Logo.png`,
@ -402,9 +412,9 @@ class Feed extends Model {
*/ */
static async createFeedForSeries(userId, seriesExpanded, slug, serverAddress, feedOptions) { static async createFeedForSeries(userId, seriesExpanded, slug, serverAddress, feedOptions) {
const booksWithTracks = seriesExpanded.books.filter((book) => book.includedAudioFiles.length) const booksWithTracks = seriesExpanded.books.filter((book) => book.includedAudioFiles.length)
const libraryItemMostRecentlyUpdatedAt = booksWithTracks.reduce((mostRecent, book) => { const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => {
return book.libraryItem.updatedAt > mostRecent.libraryItem.updatedAt ? book : mostRecent return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent
}).libraryItem.updatedAt }, seriesExpanded.updatedAt)
const firstBookWithCover = booksWithTracks.find((book) => book.coverPath) const firstBookWithCover = booksWithTracks.find((book) => book.coverPath)
@ -421,7 +431,7 @@ class Feed extends Model {
slug, slug,
entityType: 'series', entityType: 'series',
entityId: seriesExpanded.id, entityId: seriesExpanded.id,
entityUpdatedAt: libraryItemMostRecentlyUpdatedAt, entityUpdatedAt,
serverAddress, serverAddress,
feedURL: `/feed/${slug}`, feedURL: `/feed/${slug}`,
imageURL: firstBookWithCover?.coverPath ? `/feed/${slug}/cover${Path.extname(firstBookWithCover.coverPath)}` : `/Logo.png`, imageURL: firstBookWithCover?.coverPath ? `/feed/${slug}/cover${Path.extname(firstBookWithCover.coverPath)}` : `/Logo.png`,