diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 8f573312..7849d2fc 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -1,3 +1,4 @@ +const fs = require('../libs/fsExtra') const Logger = require('../Logger') const SocketAuthority = require('../SocketAuthority') @@ -178,7 +179,15 @@ class LibraryItemController { // GET api/items/:id/cover async getCover(req, res) { - let { query: { width, height, format }, libraryItem } = req + const { query: { width, height, format, raw }, libraryItem } = req + + if (raw) { // any value + if (!libraryItem.media.coverPath || !await fs.pathExists(libraryItem.media.coverPath)) { + return res.sendStatus(404) + } + + return res.sendFile(libraryItem.media.coverPath) + } const options = { format: format || (reqSupportsWebp(req) ? 'webp' : 'jpeg'), diff --git a/server/managers/CacheManager.js b/server/managers/CacheManager.js index ce48ffc3..948d152f 100644 --- a/server/managers/CacheManager.js +++ b/server/managers/CacheManager.js @@ -47,7 +47,7 @@ class CacheManager { res.type(`image/${format}`) - var path = Path.join(this.CoverCachePath, `${libraryItem.id}_${width}${height ? `x${height}` : ''}`) + '.' + format + const path = Path.join(this.CoverCachePath, `${libraryItem.id}_${width}${height ? `x${height}` : ''}`) + '.' + format // Cache exists if (await fs.pathExists(path)) { @@ -66,7 +66,7 @@ class CacheManager { return res.sendStatus(500) } - let writtenFile = await resizeImage(libraryItem.media.coverPath, path, width, height) + const writtenFile = await resizeImage(libraryItem.media.coverPath, path, width, height) if (!writtenFile) return res.sendStatus(500) // Set owner and permissions of cache image