mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Addressed feedback changes
This commit is contained in:
parent
9350c5513e
commit
57a5005197
@ -98,13 +98,10 @@ export default {
|
|||||||
if (!this.itemData.title) return ''
|
if (!this.itemData.title) return ''
|
||||||
if (this.isPodcast) return this.itemData.title
|
if (this.isPodcast) return this.itemData.title
|
||||||
|
|
||||||
if (this.itemData.series && this.itemData.author) {
|
const outputPathParts = [this.itemData.author, this.itemData.series, this.itemData.title]
|
||||||
return Path.join(this.itemData.author, this.itemData.series, this.itemData.title)
|
const cleanedOutputPathParts = outputPathParts.filter(Boolean).map(part => this.$sanitizeFilename(part))
|
||||||
} else if (this.itemData.author) {
|
|
||||||
return Path.join(this.itemData.author, this.itemData.title)
|
return Path.join(...cleanedOutputPathParts)
|
||||||
} else {
|
|
||||||
return this.itemData.title
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
isNonInteractable() {
|
isNonInteractable() {
|
||||||
return this.isUploading || this.isFetchingMetadata
|
return this.isUploading || this.isFetchingMetadata
|
||||||
|
@ -77,6 +77,7 @@ Vue.prototype.$sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||||||
.replace(lineBreaks, replacement)
|
.replace(lineBreaks, replacement)
|
||||||
.replace(windowsReservedRe, replacement)
|
.replace(windowsReservedRe, replacement)
|
||||||
.replace(windowsTrailingRe, replacement)
|
.replace(windowsTrailingRe, replacement)
|
||||||
|
.replace(/\s+/g, ' ') // Replace consecutive spaces with a single space
|
||||||
|
|
||||||
// Check if basename is too many bytes
|
// Check if basename is too many bytes
|
||||||
const ext = Path.extname(sanitized) // separate out file extension
|
const ext = Path.extname(sanitized) // separate out file extension
|
||||||
|
@ -8,6 +8,7 @@ const Database = require('../Database')
|
|||||||
const libraryItemFilters = require('../utils/queries/libraryItemFilters')
|
const libraryItemFilters = require('../utils/queries/libraryItemFilters')
|
||||||
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
||||||
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
||||||
|
const { sanitizeFilename } = require('../utils/fileUtils')
|
||||||
|
|
||||||
const TaskManager = require('../managers/TaskManager')
|
const TaskManager = require('../managers/TaskManager')
|
||||||
|
|
||||||
@ -32,12 +33,9 @@ class MiscController {
|
|||||||
Logger.error('Invalid request, no files')
|
Logger.error('Invalid request, no files')
|
||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = Object.values(req.files)
|
const files = Object.values(req.files)
|
||||||
const title = req.body.title
|
const { title, author, series, folder: folderId, library: libraryId } = req.body
|
||||||
const author = req.body.author
|
|
||||||
const series = req.body.series
|
|
||||||
const libraryId = req.body.library
|
|
||||||
const folderId = req.body.folder
|
|
||||||
|
|
||||||
const library = await Database.libraryModel.getOldById(libraryId)
|
const library = await Database.libraryModel.getOldById(libraryId)
|
||||||
if (!library) {
|
if (!library) {
|
||||||
@ -52,43 +50,29 @@ class MiscController {
|
|||||||
return res.status(500).send(`Invalid post data`)
|
return res.status(500).send(`Invalid post data`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For setting permissions recursively
|
// Podcasts should only be one folder deep
|
||||||
let outputDirectory = ''
|
const outputDirectoryParts = library.isPodcast ? [title] : [author, series, title]
|
||||||
let firstDirPath = ''
|
// `.filter(Boolean)` to strip out all the potentially missing details (eg: `author`)
|
||||||
|
// before sanitizing all the directory parts to remove illegal chars and finally prepending
|
||||||
if (library.isPodcast) { // Podcasts only in 1 folder
|
// the base folder path
|
||||||
outputDirectory = Path.join(folder.fullPath, title)
|
const cleanedOutputDirectoryParts = outputDirectoryParts.filter(Boolean).map(part => sanitizeFilename(part))
|
||||||
firstDirPath = outputDirectory
|
const outputDirectory = Path.join(...[folder.fullPath, ...cleanedOutputDirectoryParts])
|
||||||
} else {
|
|
||||||
firstDirPath = Path.join(folder.fullPath, author)
|
|
||||||
if (series && author) {
|
|
||||||
outputDirectory = Path.join(folder.fullPath, author, series, title)
|
|
||||||
} else if (author) {
|
|
||||||
outputDirectory = Path.join(folder.fullPath, author, title)
|
|
||||||
} else {
|
|
||||||
outputDirectory = Path.join(folder.fullPath, title)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await fs.pathExists(outputDirectory)) {
|
|
||||||
Logger.error(`[Server] Upload directory "${outputDirectory}" already exists`)
|
|
||||||
return res.status(500).send(`Directory "${outputDirectory}" already exists`)
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.ensureDir(outputDirectory)
|
await fs.ensureDir(outputDirectory)
|
||||||
|
|
||||||
Logger.info(`Uploading ${files.length} files to`, outputDirectory)
|
Logger.info(`Uploading ${files.length} files to`, outputDirectory)
|
||||||
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (const file of files) {
|
||||||
var file = files[i]
|
const path = Path.join(outputDirectory, sanitizeFilename(file.name))
|
||||||
|
|
||||||
var path = Path.join(outputDirectory, file.name)
|
await file.mv(path)
|
||||||
await file.mv(path).then(() => {
|
.then(() => {
|
||||||
return true
|
return true
|
||||||
}).catch((error) => {
|
})
|
||||||
Logger.error('Failed to move file', path, error)
|
.catch((error) => {
|
||||||
return false
|
Logger.error('Failed to move file', path, error)
|
||||||
})
|
return false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
@ -691,4 +675,4 @@ class MiscController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = new MiscController()
|
module.exports = new MiscController()
|
||||||
|
@ -308,6 +308,7 @@ module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||||||
.replace(lineBreaks, replacement)
|
.replace(lineBreaks, replacement)
|
||||||
.replace(windowsReservedRe, replacement)
|
.replace(windowsReservedRe, replacement)
|
||||||
.replace(windowsTrailingRe, replacement)
|
.replace(windowsTrailingRe, replacement)
|
||||||
|
.replace(/\s+/g, ' ') // Replace consecutive spaces with a single space
|
||||||
|
|
||||||
// Check if basename is too many bytes
|
// Check if basename is too many bytes
|
||||||
const ext = Path.extname(sanitized) // separate out file extension
|
const ext = Path.extname(sanitized) // separate out file extension
|
||||||
|
Loading…
Reference in New Issue
Block a user