From 8162c30e0d79c49349d35ba2720b9e281e97568a Mon Sep 17 00:00:00 2001 From: jacobiclark Date: Wed, 16 Oct 2024 11:35:27 -0700 Subject: [PATCH] wip: Updated SDS validation function to include new metadata files --- .../src/scripts/others/tab-effects.js | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/scripts/others/tab-effects.js b/src/renderer/src/scripts/others/tab-effects.js index 484e179ef..29ec01bce 100644 --- a/src/renderer/src/scripts/others/tab-effects.js +++ b/src/renderer/src/scripts/others/tab-effects.js @@ -1713,11 +1713,10 @@ const recursive_structure_create_include_manifest = ( return; }; -// Function to verify if a local folder is a SPARC folder -// If no high level folders or any possible metadata files -// are found the folder is marked as invalid +// Function to verify if a local folder is a valid SPARC folder +// A valid SPARC folder must contain at least one high-level folder or metadata file. window.verifySparcFolder = (rootFolderPath, type) => { - const possibleMetadataFiles = [ + const metadataFiles = [ "submission", "dataset_description", "subjects", @@ -1733,20 +1732,18 @@ window.verifySparcFolder = (rootFolderPath, type) => { "manifest", ]; - // Get the contents of the root folder - const entries = window.fs.readdirSync(rootFolderPath); + const folderContents = window.fs + .readdirSync(rootFolderPath) + .map((item) => window.path.parse(item).name.toLowerCase()); + const highLevelFolders = window.highLevelFolders.map((folder) => folder.toLowerCase()); - // Check if the folder contains any high level folders or metadata files (case-insensitive) - const isValidItem = (item) => { - const itemName = window.path.parse(item).name.toLowerCase(); // Convert to lowercase - return ( - window.highLevelFolders.map((folder) => folder.toLowerCase()).includes(itemName) || - possibleMetadataFiles.map((file) => file.toLowerCase()).includes(itemName) || - (type === "pennsieve" && item[0] !== ".") - ); - }; + const isValidItem = (item) => + highLevelFolders.includes(item) || + metadataFiles.includes(item) || + (type === "pennsieve" && !item.startsWith(".")); - return entries.some(isValidItem); + // Returns true if the folder contains at least one valid item (high level folder or metadata file) + return folderContents.some(isValidItem); }; // function similar to window.transitionSubQuestions, but for buttons