1
import { Request, Response, NextFunction } from 'express'
3
import nodesService from '../../services/nodes'
4
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
5
import { StatusCodes } from 'http-status-codes'
7
const getAllNodes = async (req: Request, res: Response, next: NextFunction) => {
9
const apiResponse = await nodesService.getAllNodes()
10
return res.json(apiResponse)
16
const getNodeByName = async (req: Request, res: Response, next: NextFunction) => {
18
if (typeof req.params === 'undefined' || !req.params.name) {
19
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getNodeByName - name not provided!`)
21
const apiResponse = await nodesService.getNodeByName(req.params.name)
22
return res.json(apiResponse)
28
const getNodesByCategory = async (req: Request, res: Response, next: NextFunction) => {
30
if (typeof req.params.name === 'undefined' || req.params.name === '') {
31
throw new InternalFlowiseError(
32
StatusCodes.PRECONDITION_FAILED,
33
`Error: nodesController.getNodesByCategory - name not provided!`
36
const name = _.unescape(req.params.name)
37
const apiResponse = await nodesService.getAllNodesForCategory(name)
38
return res.json(apiResponse)
44
const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction) => {
46
if (typeof req.params === 'undefined' || !req.params.name) {
47
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getSingleNodeIcon - name not provided!`)
49
const apiResponse = await nodesService.getSingleNodeIcon(req.params.name)
50
return res.sendFile(apiResponse)
56
const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: NextFunction) => {
59
throw new InternalFlowiseError(
60
StatusCodes.PRECONDITION_FAILED,
61
`Error: nodesController.getSingleNodeAsyncOptions - body not provided!`
64
if (typeof req.params === 'undefined' || !req.params.name) {
65
throw new InternalFlowiseError(
66
StatusCodes.PRECONDITION_FAILED,
67
`Error: nodesController.getSingleNodeAsyncOptions - name not provided!`
70
const apiResponse = await nodesService.getSingleNodeAsyncOptions(req.params.name, req.body)
71
return res.json(apiResponse)
77
const executeCustomFunction = async (req: Request, res: Response, next: NextFunction) => {
80
throw new InternalFlowiseError(
81
StatusCodes.PRECONDITION_FAILED,
82
`Error: nodesController.executeCustomFunction - body not provided!`
85
const apiResponse = await nodesService.executeCustomFunction(req.body)
86
return res.json(apiResponse)
96
getSingleNodeAsyncOptions,
97
executeCustomFunction,