mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-19 00:18:56 +01:00
Move cover path func to LibraryItem model
This commit is contained in:
parent
c25acb41fa
commit
7a1623e6a1
@ -23,7 +23,7 @@ class Auth {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the request should not be authenticated.
|
* Checks if the request should not be authenticated.
|
||||||
* @param {import('express').Request} req
|
* @param {Request} req
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -808,28 +808,6 @@ class Database {
|
|||||||
return `${normalizedColumn} LIKE ${pattern}`
|
return `${normalizedColumn} LIKE ${pattern}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLibraryItemCoverPath(libraryItemId) {
|
|
||||||
const libraryItem = await this.libraryItemModel.findByPk(libraryItemId, {
|
|
||||||
attributes: ['id', 'mediaType', 'mediaId', 'libraryId'],
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: this.bookModel,
|
|
||||||
attributes: ['id', 'coverPath']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
model: this.podcastModel,
|
|
||||||
attributes: ['id', 'coverPath']
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
if (!libraryItem) {
|
|
||||||
Logger.warn(`[Database] getCover: Library item "${libraryItemId}" does not exist`)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return libraryItem.media.coverPath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new Database()
|
module.exports = new Database()
|
||||||
|
@ -350,7 +350,7 @@ class LibraryItemController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
const coverPath = await Database.getLibraryItemCoverPath(libraryItemId)
|
const coverPath = await Database.libraryItemModel.getCoverPath(libraryItemId)
|
||||||
if (!coverPath || !(await fs.pathExists(coverPath))) {
|
if (!coverPath || !(await fs.pathExists(coverPath))) {
|
||||||
return res.sendStatus(404)
|
return res.sendStatus(404)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class CacheManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cached cover does not exist, generate it
|
// Cached cover does not exist, generate it
|
||||||
const coverPath = await Database.getLibraryItemCoverPath(libraryItemId)
|
const coverPath = await Database.libraryItemModel.getCoverPath(libraryItemId)
|
||||||
if (!coverPath || !(await fs.pathExists(coverPath))) {
|
if (!coverPath || !(await fs.pathExists(coverPath))) {
|
||||||
return res.sendStatus(404)
|
return res.sendStatus(404)
|
||||||
}
|
}
|
||||||
|
@ -863,6 +863,33 @@ class LibraryItem extends Model {
|
|||||||
return this.getOldLibraryItem(libraryItem)
|
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
|
* @param {import('sequelize').FindOptions} options
|
||||||
|
Loading…
Reference in New Issue
Block a user