Update library item cover PATCH endpoint to require the cover path to be in the library item libraryFiles array

This commit is contained in:
advplyr committed 2026-09-21 16:07:41 -05:00
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)
+10
View File
@@ -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}"`)