mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-27 10:52:47 +01:00
Update library item cover PATCH endpoint to require the cover path to be in the library item libraryFiles array
This commit is contained in:
1 parent
e874d31e64
commit
8463b8426a
2 files changed
+14
No files matched your search
@@ -335,6 +335,9 @@ class LibraryItemController {
|
||||
/**
|
||||
* PATCH: /api/items/:id/cover
|
||||
*
|
||||
* This is used when updating the cover to a local image library file for the library item
|
||||
* TODO: In the next API this should be using an inode or similar instead of a file path
|
||||
*
|
||||
* @param {LibraryItemControllerRequest} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
@@ -343,6 +346,7 @@ class LibraryItemController {
|
||||
return res.status(400).send('Invalid request no cover path')
|
||||
}
|
||||
|
||||
// Must be a cover file path inside the libraryFiles array
|
||||
const validationResult = await CoverManager.validateCoverPath(req.body.cover, req.libraryItem)
|
||||
if (validationResult.error) {
|
||||
return res.status(500).send(validationResult.error)
|
||||
|
||||
@@ -138,6 +138,16 @@ class CoverManager {
|
||||
}
|
||||
}
|
||||
coverPath = filePathToPOSIX(coverPath)
|
||||
|
||||
// Must already have been scanned in for the library item
|
||||
const isLibraryItemFile = libraryItem.libraryFiles?.some((lf) => filePathToPOSIX(lf.metadata?.path) === coverPath)
|
||||
if (!isLibraryItemFile) {
|
||||
Logger.error(`[CoverManager] validate cover path is not a library item file "${coverPath}"`)
|
||||
return {
|
||||
error: 'Invalid cover path'
|
||||
}
|
||||
}
|
||||
|
||||
// Cover path already set on media
|
||||
if (libraryItem.media.coverPath == coverPath) {
|
||||
Logger.debug(`[CoverManager] validate cover path already set "${coverPath}"`)
|
||||
|
||||
Reference in new issue
Block a user