mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-05-09 01:16:46 +02:00
clean up
This commit is contained in:
parent
9b79aab4d5
commit
3c9966e849
@ -1433,8 +1433,8 @@ class LibraryController {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
if(req.query.ids === undefined) {
|
||||
res.status(400).send('Library not found')
|
||||
if(req.query.ids === undefined || req.query.ids === '') {
|
||||
res.status(400).send('Library items not found')
|
||||
}
|
||||
|
||||
const itemIds = req.query.ids.split(',')
|
||||
@ -1452,24 +1452,18 @@ class LibraryController {
|
||||
|
||||
const filename = `LibraryItems-${Date.now()}.zip`
|
||||
const libraryItemPaths = libraryItems.map((li) => li.path)
|
||||
|
||||
|
||||
if (!libraryItemPaths.length) {
|
||||
Logger.warn(`[LibraryItemController] No library items found for ids "${itemIds}"`)
|
||||
return res.status(404).send('Library items not found')
|
||||
}
|
||||
|
||||
try {
|
||||
await zipHelpers.zipDirectoriesPipe(libraryItemPaths, filename, res)
|
||||
Logger.info(`[LibraryItemController] Downloaded item "${filename}" at "${libraryItemPaths}"`)
|
||||
} catch (error) {
|
||||
Logger.error(`[LibraryItemController] Download failed for item "${filename}" at "${libraryItemPaths}"`, error)
|
||||
LibraryController.handleDownloadError(error, res)
|
||||
}
|
||||
}
|
||||
|
||||
static handleDownloadError(error, res) {
|
||||
if (!res.headersSent) {
|
||||
if (error.code === 'ENOENT') {
|
||||
return res.status(404).send('File not found')
|
||||
} else {
|
||||
return res.status(500).send('Download failed')
|
||||
}
|
||||
zipHelpers.handleDownloadError(error, res)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,3 +123,20 @@ module.exports.zipDirectoriesPipe = (paths, filename, res) => {
|
||||
archive.finalize()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors that occur during the download process.
|
||||
*
|
||||
* @param error
|
||||
* @param res
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports.handleDownloadError = (error, res) => {
|
||||
if (!res.headersSent) {
|
||||
if (error.code === 'ENOENT') {
|
||||
return res.status(404).send('File not found')
|
||||
} else {
|
||||
return res.status(500).send('Download failed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user