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
+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
}