From f3a453be20ff4075e28e4c5a575905958be76ee9 Mon Sep 17 00:00:00 2001 From: ic1415 <63030270+ic1415@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:19:28 -0400 Subject: [PATCH] Update LibraryItemController.js Additional logging for single file downloads coming from download function --- server/controllers/LibraryItemController.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index ba0e1050..52416e42 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -109,6 +109,9 @@ class LibraryItemController { * @param {import('express').Response} res */ download(req, res) { + const libraryItemPath = req.libraryItem.path + const itemTitle = req.libraryItem.media.metadata.title + if (!req.user.canDownload) { Logger.warn('User attempted to download without permission', req.user) return res.sendStatus(403) @@ -117,17 +120,15 @@ class LibraryItemController { // If library item is a single file in root dir then no need to zip if (req.libraryItem.isFile) { // Express does not set the correct mimetype for m4b files so use our defined mimetypes if available - const audioMimeType = getAudioMimeTypeFromExtname(Path.extname(req.libraryItem.path)) + const audioMimeType = getAudioMimeTypeFromExtname(Path.extname(libraryItemPath)) if (audioMimeType) { res.setHeader('Content-Type', audioMimeType) } - + Logger.info(`[LibraryItemController] User "${req.user.username}" requested download for item "${itemTitle}" at "${libraryItemPath}"`) res.download(req.libraryItem.path, req.libraryItem.relPath) return } - const libraryItemPath = req.libraryItem.path - const itemTitle = req.libraryItem.media.metadata.title Logger.info(`[LibraryItemController] User "${req.user.username}" requested download for item "${itemTitle}" at "${libraryItemPath}"`) const filename = `${itemTitle}.zip` zipHelpers.zipDirectoryPipe(libraryItemPath, filename, res)