Feature: Option to add apikeys to the DB instead of api.json. (#2783)

* Feature: Option to add apikeys to the DB instead of api.json.

* add api storage type env variable

* code cleanup and simplification.

* md table fixes

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Vinod Kiran
2024-07-26 22:22:12 +05:30
committed by GitHub
parent e5018d2743
commit 2dd1791ec2
26 changed files with 647 additions and 38 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
import { Request } from 'express'
import { ChatFlow } from '../database/entities/ChatFlow'
import { getAPIKeys, compareKeys } from './apiKey'
import { compareKeys } from './apiKey'
import apikeyService from '../services/apikey'
/**
* Validate API Key
* @param {Request} req
@@ -17,8 +17,8 @@ export const utilValidateKey = async (req: Request, chatflow: ChatFlow) => {
const suppliedKey = authorizationHeader.split(`Bearer `).pop()
if (suppliedKey) {
const keys = await getAPIKeys()
const apiSecret = keys.find((key) => key.id === chatFlowApiKeyId)?.apiSecret
const keys = await apikeyService.getAllApiKeys()
const apiSecret = keys.find((key: any) => key.id === chatFlowApiKeyId)?.apiSecret
if (!compareKeys(apiSecret, suppliedKey)) return false
return true
}