mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 01:09:26 +02:00
clean up
This commit is contained in:
parent
9b79aab4d5
commit
3c9966e849
2 changed files with 25 additions and 14 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue