Skip to content

Commit

Permalink
wip: Updated SDS validation function to include new metadata files
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Oct 16, 2024
1 parent 01f1071 commit 8162c30
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/renderer/src/scripts/others/tab-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 8162c30

Please sign in to comment.