Flowise

Форк
0
99 строк · 3.4 Кб
1
import { Request, Response, NextFunction } from 'express'
2
import _ from 'lodash'
3
import nodesService from '../../services/nodes'
4
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
5
import { StatusCodes } from 'http-status-codes'
6

7
const getAllNodes = async (req: Request, res: Response, next: NextFunction) => {
8
    try {
9
        const apiResponse = await nodesService.getAllNodes()
10
        return res.json(apiResponse)
11
    } catch (error) {
12
        next(error)
13
    }
14
}
15

16
const getNodeByName = async (req: Request, res: Response, next: NextFunction) => {
17
    try {
18
        if (typeof req.params === 'undefined' || !req.params.name) {
19
            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getNodeByName - name not provided!`)
20
        }
21
        const apiResponse = await nodesService.getNodeByName(req.params.name)
22
        return res.json(apiResponse)
23
    } catch (error) {
24
        next(error)
25
    }
26
}
27

28
const getNodesByCategory = async (req: Request, res: Response, next: NextFunction) => {
29
    try {
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!`
34
            )
35
        }
36
        const name = _.unescape(req.params.name)
37
        const apiResponse = await nodesService.getAllNodesForCategory(name)
38
        return res.json(apiResponse)
39
    } catch (error) {
40
        next(error)
41
    }
42
}
43

44
const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction) => {
45
    try {
46
        if (typeof req.params === 'undefined' || !req.params.name) {
47
            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getSingleNodeIcon - name not provided!`)
48
        }
49
        const apiResponse = await nodesService.getSingleNodeIcon(req.params.name)
50
        return res.sendFile(apiResponse)
51
    } catch (error) {
52
        next(error)
53
    }
54
}
55

56
const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: NextFunction) => {
57
    try {
58
        if (!req.body) {
59
            throw new InternalFlowiseError(
60
                StatusCodes.PRECONDITION_FAILED,
61
                `Error: nodesController.getSingleNodeAsyncOptions - body not provided!`
62
            )
63
        }
64
        if (typeof req.params === 'undefined' || !req.params.name) {
65
            throw new InternalFlowiseError(
66
                StatusCodes.PRECONDITION_FAILED,
67
                `Error: nodesController.getSingleNodeAsyncOptions - name not provided!`
68
            )
69
        }
70
        const apiResponse = await nodesService.getSingleNodeAsyncOptions(req.params.name, req.body)
71
        return res.json(apiResponse)
72
    } catch (error) {
73
        next(error)
74
    }
75
}
76

77
const executeCustomFunction = async (req: Request, res: Response, next: NextFunction) => {
78
    try {
79
        if (!req.body) {
80
            throw new InternalFlowiseError(
81
                StatusCodes.PRECONDITION_FAILED,
82
                `Error: nodesController.executeCustomFunction - body not provided!`
83
            )
84
        }
85
        const apiResponse = await nodesService.executeCustomFunction(req.body)
86
        return res.json(apiResponse)
87
    } catch (error) {
88
        next(error)
89
    }
90
}
91

92
export default {
93
    getAllNodes,
94
    getNodeByName,
95
    getSingleNodeIcon,
96
    getSingleNodeAsyncOptions,
97
    executeCustomFunction,
98
    getNodesByCategory
99
}
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.