mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
working: update file-graph-algorithm
This commit is contained in:
1 parent
ab570e9c1b
commit
821896f292
5 files changed
+162
-36
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user