* Create a child tree * @param {Tree} parent * @param {File} item * @param {Tree} root
(parent, item, root)
| 406 | * @param {Tree} root |
| 407 | */ |
| 408 | async 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 | |
| 451 | export class Tree { |
| 452 | /**@type {string}*/ |
no test coverage detected