mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 11:21:36 +00:00
Remove download logic from LibraryItemController
This commit is contained in:
parent
9c63db4a3c
commit
7f5a6fc917
1 changed files with 22 additions and 38 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue