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 1/3] 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) From ef2d736b200b281f350bb6c34b130f3da8906f87 Mon Sep 17 00:00:00 2001 From: ic1415 <63030270+ic1415@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:33:56 -0400 Subject: [PATCH 2/3] Update LibraryItemController.js standardizing log messages for all download cases --- server/controllers/LibraryItemController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 52416e42..93047e86 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -716,7 +716,7 @@ class LibraryItemController { return res.sendStatus(403) } - Logger.info(`[LibraryItemController] User "${req.user.username}" requested file download at "${libraryFile.metadata.path}"`) + Logger.info(`[LibraryItemController] User "${req.user.username}" requested download for item "${req.libraryItem.media.metadata.title}" at "${libraryFile.metadata.path}"`) if (global.XAccel) { const encodedURI = encodeUriPath(global.XAccel + libraryFile.metadata.path) From b55d8250ccac29fb8e7aebfdd53d0f8fd2d0cd6b Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 9 Aug 2024 16:48:21 -0500 Subject: [PATCH 3/3] Download log update --- server/controllers/LibraryItemController.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 93047e86..d354d236 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -109,13 +109,12 @@ 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) } + const libraryItemPath = req.libraryItem.path + const itemTitle = req.libraryItem.media.metadata.title // If library item is a single file in root dir then no need to zip if (req.libraryItem.isFile) { @@ -125,7 +124,7 @@ class LibraryItemController { 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) + res.download(libraryItemPath, req.libraryItem.relPath) return } @@ -716,7 +715,7 @@ class LibraryItemController { return res.sendStatus(403) } - Logger.info(`[LibraryItemController] User "${req.user.username}" requested download for item "${req.libraryItem.media.metadata.title}" at "${libraryFile.metadata.path}"`) + Logger.info(`[LibraryItemController] User "${req.user.username}" requested download for item "${req.libraryItem.media.metadata.title}" file at "${libraryFile.metadata.path}"`) if (global.XAccel) { const encodedURI = encodeUriPath(global.XAccel + libraryFile.metadata.path)