Remove download logic from LibraryItemController

This commit is contained in:
Greg Lorenzen 2024-12-10 02:02:28 +00:00
parent 9c63db4a3c
commit 7f5a6fc917

View file

@ -157,7 +157,10 @@ class LibraryItemController {
* @param {Response} res
*/
async download(req, res) {
const handleDownload = async (req, res) => {
if (!req.user.canDownload) {
Logger.warn(`User "${req.user.username}" attempted to download without permission`)
return res.sendStatus(403)
}
const libraryItemPath = req.libraryItem.path
const itemTitle = req.libraryItem.media.metadata.title
@ -179,29 +182,10 @@ class LibraryItemController {
Logger.info(`[LibraryItemController] Downloaded item "${itemTitle}" at "${libraryItemPath}"`)
} catch (error) {
Logger.error(`[LibraryItemController] Download failed for item "${itemTitle}" at "${libraryItemPath}"`, error)
res.status(500).send('Failed to download the item')
LibraryItemController.handleDownloadError(error, res)
}
}
if (req.query.share) {
// Find matching MediaItemShare based on slug
const mediaItemShare = await ShareManager.findBySlug(req.query.share)
if (mediaItemShare) {
// If the isDownloadable bool is true, download the file
if (mediaItemShare.isDownloadable) {
return handleDownload(req, res)
}
}
}
if (!req.user.canDownload) {
Logger.warn(`User "${req.user.username}" attempted to download without permission`)
return res.sendStatus(403)
}
return handleDownload(req, res)
}
/**
* PATCH: /items/:id/media
* Update media for a library item. Will create new authors & series when necessary