mirror of
https://github.com/FlowiseAI/Flowise.git
synced 2026-10-12 02:02:17 +00:00
refactor: Extract loadNodesFromDir() from NodesPool for reuse (#5904)
Move node-loading and filtering logic into a public loadNodesFromDir(dir) method so extensions can load nodes from additional directories
This commit is contained in:
@@ -24,11 +24,20 @@ export class NodesPool {
|
||||
* Initialize nodes
|
||||
*/
|
||||
private async initializeNodes() {
|
||||
const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : []
|
||||
const packagePath = getNodeModulesPackagePath('flowise-components')
|
||||
const nodesPath = path.join(packagePath, 'dist', 'nodes')
|
||||
const nodeFiles = await this.getFiles(nodesPath)
|
||||
return Promise.all(
|
||||
const nodes = await this.loadNodesFromDir(nodesPath)
|
||||
Object.assign(this.componentNodes, nodes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and filter nodes from a directory.
|
||||
*/
|
||||
async loadNodesFromDir(dir: string): Promise<IComponentNodes> {
|
||||
const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : []
|
||||
const nodes: IComponentNodes = {}
|
||||
const nodeFiles = await this.getFiles(dir)
|
||||
await Promise.all(
|
||||
nodeFiles.map(async (file) => {
|
||||
if (file.endsWith('.js')) {
|
||||
try {
|
||||
@@ -69,7 +78,7 @@ export class NodesPool {
|
||||
const isDisabled = disabled_nodes.includes(newNodeInstance.name)
|
||||
|
||||
if (conditionOne && conditionTwo && !isDisabled) {
|
||||
this.componentNodes[newNodeInstance.name] = newNodeInstance
|
||||
nodes[newNodeInstance.name] = newNodeInstance
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -78,6 +87,7 @@ export class NodesPool {
|
||||
}
|
||||
})
|
||||
)
|
||||
return nodes
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user