mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-20 18:59:37 +00:00
Update PlaybackSession to use new library item model
This commit is contained in:
parent
d205c6f734
commit
c251f1899d
16 changed files with 284 additions and 193 deletions
|
|
@ -497,6 +497,57 @@ class LibraryItem extends Model {
|
|||
return libraryItem
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('sequelize').WhereOptions} where
|
||||
* @param {import('sequelize').IncludeOptions} [include]
|
||||
* @returns {Promise<LibraryItemExpanded>}
|
||||
*/
|
||||
static async findOneExpanded(where, include = null) {
|
||||
const libraryItem = await this.findOne({
|
||||
where,
|
||||
include
|
||||
})
|
||||
if (!libraryItem) {
|
||||
Logger.error(`[LibraryItem] Library item not found`)
|
||||
return null
|
||||
}
|
||||
|
||||
if (libraryItem.mediaType === 'podcast') {
|
||||
libraryItem.media = await libraryItem.getMedia({
|
||||
include: [
|
||||
{
|
||||
model: this.sequelize.models.podcastEpisode
|
||||
}
|
||||
]
|
||||
})
|
||||
} else {
|
||||
libraryItem.media = await libraryItem.getMedia({
|
||||
include: [
|
||||
{
|
||||
model: this.sequelize.models.author,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: this.sequelize.models.series,
|
||||
through: {
|
||||
attributes: ['id', 'sequence']
|
||||
}
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'],
|
||||
[this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
if (!libraryItem.media) return null
|
||||
return libraryItem
|
||||
}
|
||||
|
||||
/**
|
||||
* Get old library item by id
|
||||
* @param {string} libraryItemId
|
||||
|
|
@ -1176,6 +1227,22 @@ class LibraryItem extends Model {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the track list to be used in client audio players
|
||||
* AudioTrack is the AudioFile with startOffset and contentUrl
|
||||
* Podcasts must have an episodeId to get the track list
|
||||
*
|
||||
* @param {string} [episodeId]
|
||||
* @returns {import('./Book').AudioTrack[]}
|
||||
*/
|
||||
getTrackList(episodeId) {
|
||||
if (!this.media) {
|
||||
Logger.error(`[LibraryItem] getTrackList: Library item "${this.id}" does not have media`)
|
||||
return []
|
||||
}
|
||||
return this.media.getTracklist(this.id, episodeId)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} ino
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue