mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-18 09:21:31 +00:00
Merge 700d1e8459 into 47ea6b5092
This commit is contained in:
commit
da9f070ffe
1 changed files with 18 additions and 10 deletions
|
|
@ -78,22 +78,30 @@ class MiscController {
|
||||||
const cleanedOutputDirectoryParts = outputDirectoryParts.filter(Boolean).map((part) => sanitizeFilename(part))
|
const cleanedOutputDirectoryParts = outputDirectoryParts.filter(Boolean).map((part) => sanitizeFilename(part))
|
||||||
const outputDirectory = Path.join(...[folder.path, ...cleanedOutputDirectoryParts])
|
const outputDirectory = Path.join(...[folder.path, ...cleanedOutputDirectoryParts])
|
||||||
|
|
||||||
await fs.ensureDir(outputDirectory)
|
try {
|
||||||
|
await fs.ensureDir(outputDirectory)
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(`[MiscController] Failed to create upload directory "${outputDirectory}"`, error)
|
||||||
|
return res.status(500).send(`Failed to create upload directory: ${error.message}`)
|
||||||
|
}
|
||||||
|
|
||||||
Logger.info(`Uploading ${files.length} files to`, outputDirectory)
|
Logger.info(`Uploading ${files.length} files to`, outputDirectory)
|
||||||
|
|
||||||
|
const failedFiles = []
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const path = Path.join(outputDirectory, sanitizeFilename(file.name))
|
const path = Path.join(outputDirectory, sanitizeFilename(file.name))
|
||||||
|
|
||||||
await file
|
await file.mv(path).catch((error) => {
|
||||||
.mv(path)
|
Logger.error('Failed to move file', path, error)
|
||||||
.then(() => {
|
failedFiles.push(`${file.name} (${error.message})`)
|
||||||
return true
|
})
|
||||||
})
|
}
|
||||||
.catch((error) => {
|
|
||||||
Logger.error('Failed to move file', path, error)
|
if (failedFiles.length === files.length) {
|
||||||
return false
|
return res.status(500).send(`Failed to upload files: ${failedFiles.join(', ')}`)
|
||||||
})
|
}
|
||||||
|
if (failedFiles.length) {
|
||||||
|
return res.status(500).send(`Uploaded ${files.length - failedFiles.length} of ${files.length} files. Failed: ${failedFiles.join(', ')}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue