diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 07b4ee67f..18b1dc266 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -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) diff --git a/server/managers/CoverManager.js b/server/managers/CoverManager.js index c8f889108..6233ed16e 100644 --- a/server/managers/CoverManager.js +++ b/server/managers/CoverManager.js @@ -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}"`)