MCPcopy Index your code
hub / github.com/Acode-Foundation/Acode / createChildTree

Function createChildTree

src/lib/fileList.js:408–449  ·  view source on GitHub ↗

* Create a child tree * @param {Tree} parent * @param {File} item * @param {Tree} root

(parent, item, root)

Source from the content-addressed store, hash-verified

406 * @param {Tree} root
407 */
408async function createChildTree(parent, item, root) {
409 if (!root.isConnected) return;
410 const { name, url, isDirectory, mime, type, size, modifiedDate } = item;
411 const exists = parent.children.findIndex((child) => child.url === url);
412 if (exists > -1) {
413 return;
414 }
415
416 const file = await Tree.create(
417 url,
418 name,
419 isDirectory,
420 mime || type,
421 size,
422 modifiedDate,
423 );
424 if (!root.isConnected) return;
425
426 const existingTree = getTree(Object.values(filesTree), file.url);
427
428 if (existingTree) {
429 file.children = existingTree.children;
430 parent.children.push(file);
431 return;
432 }
433
434 parent.children.push(file);
435 if (isDirectory) {
436 const ignore = picomatch.isMatch(
437 Url.join(file.path, ""),
438 settings.value.excludeFolders,
439 { matchBase: true },
440 );
441 if (ignore) return;
442
443 await getAllFiles(file, root);
444 return;
445 }
446
447 emit("push-file", file);
448 emit("add-file", file);
449}
450
451export class Tree {
452 /**@type {string}*/

Callers 1

getAllFilesFunction · 0.85

Calls 4

getTreeFunction · 0.85
getAllFilesFunction · 0.85
emitFunction · 0.70
createMethod · 0.65

Tested by

no test coverage detected