feat: Support Uploading files to existing library item folders

Adds support to uploads as specified in enhancement #1894
This commit is contained in:
Scott A Miller 2026-02-09 00:14:36 +00:00
parent b01facc034
commit 397613795f
2 changed files with 27 additions and 20 deletions

View file

@ -377,26 +377,33 @@ export default {
const itemsToUpload = [] const itemsToUpload = []
// Check if path already exists before starting upload // Check if path already exists for each file before starting upload
// uploading fails if path already exists // uploading fails if all paths already exist
for (const item of items) { for (const item of items) {
const exists = await this.$axios let filesToUpload = []
.$post(`/api/filesystem/pathexists`, { directory: item.directory, folderPath: this.selectedFolder.fullPath }) for (const file of item.files) {
.then((data) => { const exists = await this.$axios
if (data.exists) { .$post(`/api/filesystem/pathexists`, { folderPath: this.selectedFolder.fullPath, directory: item.directory, fileName: file.filepath })
if (data.libraryItemTitle) { .then((data) => {
this.$toast.error(this.$getString('ToastUploaderItemExistsInSubdirectoryError', [data.libraryItemTitle])) if (data.exists) {
} else { if (data.libraryItemTitle) {
this.$toast.error(this.$getString('ToastUploaderFilepathExistsError', [Path.join(this.selectedFolder.fullPath, item.directory)])) this.$toast.error(this.$getString('ToastUploaderItemExistsInSubdirectoryError', [data.libraryItemTitle]))
} else {
this.$toast.error(this.$getString('ToastUploaderFilepathExistsError', [Path.join(this.selectedFolder.fullPath, item.directory)]))
}
} }
} return data.exists
return data.exists })
}) .catch((error) => {
.catch((error) => { console.error('Failed to check if filepath exists', error)
console.error('Failed to check if filepath exists', error) return false
return false })
}) if (!exists) {
if (!exists) { filesToUpload.push(file)
}
}
if (filesToUpload?.length) {
item.files = filesToUpload
itemsToUpload.push(item) itemsToUpload.push(item)
} }
} }

View file

@ -88,7 +88,7 @@ class FileSystemController {
return res.sendStatus(403) return res.sendStatus(403)
} }
const { directory, folderPath } = req.body const { folderPath, directory, fileName } = req.body
if (!directory?.length || typeof directory !== 'string' || !folderPath?.length || typeof folderPath !== 'string') { if (!directory?.length || typeof directory !== 'string' || !folderPath?.length || typeof folderPath !== 'string') {
Logger.error(`[FileSystemController] Invalid request body: ${JSON.stringify(req.body)}`) Logger.error(`[FileSystemController] Invalid request body: ${JSON.stringify(req.body)}`)
return res.status(400).json({ return res.status(400).json({
@ -113,7 +113,7 @@ class FileSystemController {
return res.sendStatus(403) return res.sendStatus(403)
} }
let filepath = Path.join(libraryFolder.path, directory) let filepath = Path.join(libraryFolder.path, directory, fileName)
filepath = fileUtils.filePathToPOSIX(filepath) filepath = fileUtils.filePathToPOSIX(filepath)
// Ensure filepath is inside library folder (prevents directory traversal) // Ensure filepath is inside library folder (prevents directory traversal)