Spaces:
Running
Running
Update js/utils.js
Browse files- js/utils.js +4 -19
js/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
// Display directory structure
|
| 2 |
function displayDirectoryStructure(tree) {
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
const container = document.getElementById('directoryStructure');
|
| 7 |
container.innerHTML = '';
|
|
@@ -12,20 +13,10 @@ function displayDirectoryStructure(tree) {
|
|
| 12 |
const directoryStructure = {};
|
| 13 |
const extensionCheckboxes = {};
|
| 14 |
|
| 15 |
-
//
|
| 16 |
-
tree.sort(sortContents);
|
| 17 |
-
console.log("Sorted tree:", JSON.parse(JSON.stringify(tree)));
|
| 18 |
-
|
| 19 |
-
// Build directory structure
|
| 20 |
tree.forEach(item => {
|
| 21 |
-
// This was the problematic line. HF API only returns files.
|
| 22 |
-
// We build the directory structure from file paths.
|
| 23 |
-
// if (item.type !== 'blob') return;
|
| 24 |
-
|
| 25 |
-
console.log("Processing item:", item);
|
| 26 |
item.path = item.path.startsWith('/') ? item.path : '/' + item.path;
|
| 27 |
const pathParts = item.path.split('/');
|
| 28 |
-
console.log("Path parts:", pathParts);
|
| 29 |
let currentLevel = directoryStructure;
|
| 30 |
|
| 31 |
pathParts.forEach((part, index) => {
|
|
@@ -37,11 +28,7 @@ function displayDirectoryStructure(tree) {
|
|
| 37 |
});
|
| 38 |
});
|
| 39 |
|
| 40 |
-
console.log("Built directory structure object:", directoryStructure);
|
| 41 |
-
|
| 42 |
-
|
| 43 |
function createTreeNode(name, item, parentUl) {
|
| 44 |
-
console.log(`Creating tree node for: ${name}`, "Item:", item);
|
| 45 |
const li = document.createElement('li');
|
| 46 |
const checkbox = document.createElement('input');
|
| 47 |
checkbox.type = 'checkbox';
|
|
@@ -49,11 +36,9 @@ function displayDirectoryStructure(tree) {
|
|
| 49 |
|
| 50 |
if (typeof item === 'object' && item !== null && (!item.type || typeof item.type !== 'string')) {
|
| 51 |
// Directory node
|
| 52 |
-
console.log(` -> Identified as DIRECTORY`);
|
| 53 |
createDirectoryNode(li, checkbox, name, item, parentUl);
|
| 54 |
} else {
|
| 55 |
// File node
|
| 56 |
-
console.log(` -> Identified as FILE`);
|
| 57 |
createFileNode(li, checkbox, name, item);
|
| 58 |
}
|
| 59 |
|
|
|
|
| 1 |
// Display directory structure
|
| 2 |
function displayDirectoryStructure(tree) {
|
| 3 |
+
// FIX: Filter out explicit directory objects from HF API, as they interfere with tree building.
|
| 4 |
+
// We only need the file ('blob') paths to construct the hierarchy.
|
| 5 |
+
tree = tree.filter(item => item.type === 'blob').sort(sortContents);
|
| 6 |
|
| 7 |
const container = document.getElementById('directoryStructure');
|
| 8 |
container.innerHTML = '';
|
|
|
|
| 13 |
const directoryStructure = {};
|
| 14 |
const extensionCheckboxes = {};
|
| 15 |
|
| 16 |
+
// Build directory structure from file paths
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
tree.forEach(item => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
item.path = item.path.startsWith('/') ? item.path : '/' + item.path;
|
| 19 |
const pathParts = item.path.split('/');
|
|
|
|
| 20 |
let currentLevel = directoryStructure;
|
| 21 |
|
| 22 |
pathParts.forEach((part, index) => {
|
|
|
|
| 28 |
});
|
| 29 |
});
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
function createTreeNode(name, item, parentUl) {
|
|
|
|
| 32 |
const li = document.createElement('li');
|
| 33 |
const checkbox = document.createElement('input');
|
| 34 |
checkbox.type = 'checkbox';
|
|
|
|
| 36 |
|
| 37 |
if (typeof item === 'object' && item !== null && (!item.type || typeof item.type !== 'string')) {
|
| 38 |
// Directory node
|
|
|
|
| 39 |
createDirectoryNode(li, checkbox, name, item, parentUl);
|
| 40 |
} else {
|
| 41 |
// File node
|
|
|
|
| 42 |
createFileNode(li, checkbox, name, item);
|
| 43 |
}
|
| 44 |
|