diff --git a/client/pages/upload/index.vue b/client/pages/upload/index.vue index adc21ff90..ba60a8bb1 100644 --- a/client/pages/upload/index.vue +++ b/client/pages/upload/index.vue @@ -377,26 +377,33 @@ export default { const itemsToUpload = [] - // Check if path already exists before starting upload - // uploading fails if path already exists + // Check if path already exists for each file before starting upload + // uploading fails if all paths already exist for (const item of items) { - const exists = await this.$axios - .$post(`/api/filesystem/pathexists`, { directory: item.directory, folderPath: this.selectedFolder.fullPath }) - .then((data) => { - if (data.exists) { - if (data.libraryItemTitle) { - this.$toast.error(this.$getString('ToastUploaderItemExistsInSubdirectoryError', [data.libraryItemTitle])) - } else { - this.$toast.error(this.$getString('ToastUploaderFilepathExistsError', [Path.join(this.selectedFolder.fullPath, item.directory)])) + let filesToUpload = [] + for (const file of item.files) { + const exists = await this.$axios + .$post(`/api/filesystem/pathexists`, { folderPath: this.selectedFolder.fullPath, directory: item.directory, fileName: file.filepath }) + .then((data) => { + if (data.exists) { + if (data.libraryItemTitle) { + 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 - }) - .catch((error) => { - console.error('Failed to check if filepath exists', error) - return false - }) - if (!exists) { + return data.exists + }) + .catch((error) => { + console.error('Failed to check if filepath exists', error) + return false + }) + if (!exists) { + filesToUpload.push(file) + } + } + if (filesToUpload?.length) { + item.files = filesToUpload itemsToUpload.push(item) } } diff --git a/server/controllers/FileSystemController.js b/server/controllers/FileSystemController.js index 4b0a94b39..e7050d7f6 100644 --- a/server/controllers/FileSystemController.js +++ b/server/controllers/FileSystemController.js @@ -88,7 +88,7 @@ class FileSystemController { 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') { Logger.error(`[FileSystemController] Invalid request body: ${JSON.stringify(req.body)}`) return res.status(400).json({ @@ -113,7 +113,7 @@ class FileSystemController { return res.sendStatus(403) } - let filepath = Path.join(libraryFolder.path, directory) + let filepath = Path.join(libraryFolder.path, directory, fileName) filepath = fileUtils.filePathToPOSIX(filepath) // Ensure filepath is inside library folder (prevents directory traversal)