From f32b1cfce800764559f6544e82db79c68445c58c Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 00:05:40 +0530 Subject: [PATCH] added option to create parent directories for programmatic file drops --- .../src/modules/FileSystem/operations/upload.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index e056a3d7..8ed4eae2 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -148,6 +148,17 @@ const upload = async function(items, dirPath, options = {}){ let fileItem = entries[i].finalPath ? entries[i].finalPath : entries[i].fullPath; let [dirLevel, fileName] = [fileItem?.slice(0, fileItem?.lastIndexOf("/")), fileItem?.slice(fileItem?.lastIndexOf("/") + 1)] + // If file name is blank then we need to create only an empty directory. + // On the other hand if the file name is not blank(could be undefined), we need to create the file. + fileName != "" && files.push(entries[i]) + if (options.createFileParent && fileItem.includes('/')) { + let filePath = path.join(dirPath, dirLevel) + // Prevent duplicate parent directory creation + if(!uniqueDirs[filePath]){ + uniqueDirs[filePath] = true; + dirs.push({path: filePath}); + } + } } // stats about the upload to come if(entries[i].size !== undefined){