Refactor Feed model to create new feed for library item

This commit is contained in:
advplyr 2024-12-14 16:55:56 -06:00
parent c4610e6102
commit 9bd1f9e3d5
7 changed files with 400 additions and 112 deletions

View file

@ -106,6 +106,9 @@ class Book extends Model {
this.updatedAt
/** @type {Date} */
this.createdAt
/** @type {import('./Author')[]} - optional if expanded */
this.authors
}
static getOldBook(libraryItemExpanded) {
@ -320,6 +323,32 @@ class Book extends Model {
}
)
}
/**
* Comma separated array of author names
* Requires authors to be loaded
*
* @returns {string}
*/
get authorName() {
if (this.authors === undefined) {
Logger.error(`[Book] authorName: Cannot get authorName because authors are not loaded`)
return ''
}
return this.authors.map((au) => au.name).join(', ')
}
get includedAudioFiles() {
return this.audioFiles.filter((af) => !af.exclude)
}
get trackList() {
let startOffset = 0
return this.includedAudioFiles.map((af) => {
const track = structuredClone(af)
track.startOffset = startOffset
startOffset += track.duration
return track
})
}
}
module.exports = Book