* Load and filter nodes from a directory.
(dir: string)
| 34 | * Load and filter nodes from a directory. |
| 35 | */ |
| 36 | async loadNodesFromDir(dir: string): Promise<IComponentNodes> { |
| 37 | const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : [] |
| 38 | const nodes: IComponentNodes = {} |
| 39 | const nodeFiles = await this.getFiles(dir) |
| 40 | await Promise.all( |
| 41 | nodeFiles.map(async (file) => { |
| 42 | if (file.endsWith('.js')) { |
| 43 | try { |
| 44 | const nodeModule = await require(file) |
| 45 | |
| 46 | if (nodeModule.nodeClass) { |
| 47 | const newNodeInstance = new nodeModule.nodeClass() |
| 48 | newNodeInstance.filePath = file |
| 49 | |
| 50 | // Replace file icon with absolute path |
| 51 | if ( |
| 52 | newNodeInstance.icon && |
| 53 | (newNodeInstance.icon.endsWith('.svg') || |
| 54 | newNodeInstance.icon.endsWith('.png') || |
| 55 | newNodeInstance.icon.endsWith('.jpg')) |
| 56 | ) { |
| 57 | const filePath = file.replace(/\\/g, '/').split('/') |
| 58 | filePath.pop() |
| 59 | const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}` |
| 60 | newNodeInstance.icon = nodeIconAbsolutePath |
| 61 | |
| 62 | // Store icon path for componentCredentials |
| 63 | if (newNodeInstance.credential) { |
| 64 | for (const credName of newNodeInstance.credential.credentialNames) { |
| 65 | this.credentialIconPath[credName] = nodeIconAbsolutePath |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const skipCategories = ['Analytic', 'SpeechToText'] |
| 71 | const conditionOne = !skipCategories.includes(newNodeInstance.category) |
| 72 | |
| 73 | const isCommunityNodesAllowed = appConfig.showCommunityNodes |
| 74 | const isAuthorPresent = newNodeInstance.author |
| 75 | let conditionTwo = true |
| 76 | if (!isCommunityNodesAllowed && isAuthorPresent) conditionTwo = false |
| 77 | |
| 78 | const isDisabled = disabled_nodes.includes(newNodeInstance.name) |
| 79 | |
| 80 | if (conditionOne && conditionTwo && !isDisabled) { |
| 81 | nodes[newNodeInstance.name] = newNodeInstance |
| 82 | } |
| 83 | } |
| 84 | } catch (err) { |
| 85 | logger.error(`❌ [server]: Error during initDatabase with file ${file}:`, err) |
| 86 | } |
| 87 | } |
| 88 | }) |
| 89 | ) |
| 90 | return nodes |
| 91 | } |
| 92 | |
| 93 | /** |
no test coverage detected