Feature: interactive swagger-ui auto-generated API docs from express (#1812)

* Add interactive swagger-ui auto-generated API docs from express

* Update README.md

* Update index.ts //@ts-ignore

* Fix eslint no-console error

* Add swagger paths

* Add all end  points

* Update swagger.yml

* update swagger yml file

* update swagger config

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Octavian FlowiseAI
2024-08-25 14:22:07 +02:00
committed by GitHub
parent 0f58d31493
commit e8f5f07735
26 changed files with 3123 additions and 270 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ import {
getEndingNodes,
constructGraphs
} from '../utils'
import { utilValidateKey } from './validateKey'
import { validateChatflowAPIKey } from './validateKey'
import { databaseEntities } from '.'
import { v4 as uuidv4 } from 'uuid'
import { omit } from 'lodash'
@@ -73,7 +73,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
const userMessageDateTime = new Date()
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
const isKeyValidated = await validateChatflowAPIKey(req, chatflow)
if (!isKeyValidated) {
throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
+2 -2
View File
@@ -15,7 +15,7 @@ import {
getTelemetryFlowObj,
getStartingNodes
} from '../utils'
import { utilValidateKey } from './validateKey'
import { validateChatflowAPIKey } from './validateKey'
import { IncomingInput, INodeDirectedGraph, IReactFlowObject, chatType } from '../Interface'
import { ChatFlow } from '../database/entities/ChatFlow'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
@@ -43,7 +43,7 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
}
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
const isKeyValidated = await validateChatflowAPIKey(req, chatflow)
if (!isKeyValidated) {
throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
+23 -4
View File
@@ -2,14 +2,14 @@ import { Request } from 'express'
import { ChatFlow } from '../database/entities/ChatFlow'
import { compareKeys } from './apiKey'
import apikeyService from '../services/apikey'
/**
* Validate API Key
* Validate Chatflow API Key
* @param {Request} req
* @param {Response} res
* @param {ChatFlow} chatflow
*/
export const utilValidateKey = async (req: Request, chatflow: ChatFlow) => {
const chatFlowApiKeyId = chatflow.apikeyid
export const validateChatflowAPIKey = async (req: Request, chatflow: ChatFlow) => {
const chatFlowApiKeyId = chatflow?.apikeyid
if (!chatFlowApiKeyId) return true
const authorizationHeader = (req.headers['Authorization'] as string) ?? (req.headers['authorization'] as string) ?? ''
@@ -24,3 +24,22 @@ export const utilValidateKey = async (req: Request, chatflow: ChatFlow) => {
}
return false
}
/**
* Validate API Key
* @param {Request} req
*/
export const validateAPIKey = async (req: Request) => {
const authorizationHeader = (req.headers['Authorization'] as string) ?? (req.headers['authorization'] as string) ?? ''
if (!authorizationHeader) return false
const suppliedKey = authorizationHeader.split(`Bearer `).pop()
if (suppliedKey) {
const keys = await apikeyService.getAllApiKeys()
const apiSecret = keys.find((key: any) => key.apiKey === suppliedKey)?.apiSecret
if (!apiSecret) return false
if (!compareKeys(apiSecret, suppliedKey)) return false
return true
}
return false
}