working: update file-graph-algorithm

This commit is contained in:
Chen, Tai-Lin committed 2023-08-28 14:39:52 +08:00
1 parent 7041e89a49
commit e73113d376
5 files changed
+162 -36

No files matched your search

+5 -19
View File
@@ -1,5 +1,9 @@
import File from './file.js'
import { DuplicateItemError, ParentNotExistsError } from './errors.js'
import {
DuplicateItemError,
ParentNotExistsError,
FileNotExistsError,
} from './errors.js'
import { basename, dirname } from './utils.js'
export default class FileNode extends File {
@@ -92,22 +96,4 @@ export default class FileNode extends File {
.join('')
return `${indent}${this.name}${suffix}\n${childrenString}`
}
findNode(fileToFind) {
const pathFolders = fileToFind.path
.split('/')
.filter((folder) => folder.length > 0)
let currentNode = this
for (const folder of pathFolders) {
currentNode = currentNode.children.find(
(child) => child.name === folder && child.type === 'folder'
)
if (!currentNode) {
return null
}
}
return currentNode
}
}