mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-30 22:59:37 +02:00
allow Overwrite
This commit is contained in:
parent
ce3c08c11c
commit
7e4d0daf82
1 changed files with 10 additions and 7 deletions
|
@ -44,8 +44,9 @@ class MiscController {
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = Object.values(req.files)
|
const files = Object.values(req.files)
|
||||||
// If allowAdditionalFiles the upload endpoint allows adding items even if the type of file already exists in the library.
|
// If allowAdditionalFiles is true, the upload endpoint allows adding items even if the type of file already exists in the library.
|
||||||
let { title, author, series, folder: folderId, library: libraryId, allowAdditionalFiles } = req.body
|
// If allowOverwrite is true, it will allow overwriting existing files.
|
||||||
|
let { title, author, series, folder: folderId, library: libraryId, allowAdditionalFiles, allowOverwrite } = req.body
|
||||||
// Validate request body
|
// Validate request body
|
||||||
if (!libraryId || !folderId || typeof libraryId !== 'string' || typeof folderId !== 'string' || !title || typeof title !== 'string') {
|
if (!libraryId || !folderId || typeof libraryId !== 'string' || typeof folderId !== 'string' || !title || typeof title !== 'string') {
|
||||||
return res.status(400).send('Invalid request body')
|
return res.status(400).send('Invalid request body')
|
||||||
|
@ -80,12 +81,14 @@ 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])
|
||||||
|
|
||||||
const containsBook = allowAdditionalFiles || files.some(file => globals.SupportedEbookTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
if (allowOverwrite === undefined || allowOverwrite === null || !allowOverwrite) {
|
||||||
const containsAudio = allowAdditionalFiles || files.some(file => globals.SupportedAudioTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
const containsBook = allowAdditionalFiles || files.some(file => globals.SupportedEbookTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
|
const containsAudio = allowAdditionalFiles || files.some(file => globals.SupportedAudioTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
|
|
||||||
if ((await validatePathExists(folder, outputDirectory, files.map((f) => f.name), !containsBook, !containsAudio, true)).exists) {
|
if ((await validatePathExists(folder, outputDirectory, files.map((f) => f.name), !containsBook, !containsAudio, true)).exists) {
|
||||||
Logger.error(`Upload path already exists: ${outputDirectory}`)
|
Logger.error(`Upload path already exists: ${outputDirectory}`)
|
||||||
return res.status(400).send('Uploaded file already exists')
|
return res.status(400).send('Uploaded file already exists')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.ensureDir(outputDirectory)
|
await fs.ensureDir(outputDirectory)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue