mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Move cover path func to LibraryItem model
This commit is contained in:
parent
c25acb41fa
commit
7a1623e6a1
5 changed files with 30 additions and 25 deletions
|
@ -863,6 +863,33 @@ class LibraryItem extends Model {
|
|||
return this.getOldLibraryItem(libraryItem)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} libraryItemId
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
static async getCoverPath(libraryItemId) {
|
||||
const libraryItem = await this.findByPk(libraryItemId, {
|
||||
attributes: ['id', 'mediaType', 'mediaId', 'libraryId'],
|
||||
include: [
|
||||
{
|
||||
model: this.bookModel,
|
||||
attributes: ['id', 'coverPath']
|
||||
},
|
||||
{
|
||||
model: this.podcastModel,
|
||||
attributes: ['id', 'coverPath']
|
||||
}
|
||||
]
|
||||
})
|
||||
if (!libraryItem) {
|
||||
Logger.warn(`[LibraryItem] getCoverPath: Library item "${libraryItemId}" does not exist`)
|
||||
return null
|
||||
}
|
||||
|
||||
return libraryItem.media.coverPath
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('sequelize').FindOptions} options
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue