mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 03:11:34 +00:00
Refactor download method in LibraryItemController to handle share items
This commit is contained in:
parent
b5938b618d
commit
5eb51bf8a2
1 changed files with 38 additions and 22 deletions
|
|
@ -133,10 +133,7 @@ class LibraryItemController {
|
|||
* @param {Response} res
|
||||
*/
|
||||
async download(req, res) {
|
||||
if (!req.user.canDownload) {
|
||||
Logger.warn(`User "${req.user.username}" attempted to download without permission`)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
const handleDownload = async (req, res) => {
|
||||
const libraryItemPath = req.libraryItem.path
|
||||
const itemTitle = req.libraryItem.media.metadata.title
|
||||
|
||||
|
|
@ -158,10 +155,29 @@ class LibraryItemController {
|
|||
Logger.info(`[LibraryItemController] Downloaded item "${itemTitle}" at "${libraryItemPath}"`)
|
||||
} catch (error) {
|
||||
Logger.error(`[LibraryItemController] Download failed for item "${itemTitle}" at "${libraryItemPath}"`, error)
|
||||
LibraryItemController.handleDownloadError(error, res)
|
||||
res.status(500).send('Failed to download the item')
|
||||
}
|
||||
}
|
||||
|
||||
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