mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
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:
@@ -41,6 +41,19 @@ const updateApiKey = async (req: Request, res: Response, next: NextFunction) =>
|
||||
}
|
||||
}
|
||||
|
||||
// Import Keys from JSON file
|
||||
const importKeys = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (typeof req.body === 'undefined' || !req.body.jsonFile) {
|
||||
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.importKeys - body not provided!`)
|
||||
}
|
||||
const apiResponse = await apikeyService.importKeys(req.body)
|
||||
return res.json(apiResponse)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Delete api key
|
||||
const deleteApiKey = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
@@ -72,5 +85,6 @@ export default {
|
||||
deleteApiKey,
|
||||
getAllApiKeys,
|
||||
updateApiKey,
|
||||
verifyApiKey
|
||||
verifyApiKey,
|
||||
importKeys
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { NextFunction, Request, Response } from 'express'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
import apiKeyService from '../../services/apikey'
|
||||
import { ChatFlow } from '../../database/entities/ChatFlow'
|
||||
import { createRateLimiter } from '../../utils/rateLimit'
|
||||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { ChatflowType } from '../../Interface'
|
||||
import chatflowsService from '../../services/chatflows'
|
||||
import { getApiKey } from '../../utils/apiKey'
|
||||
import { createRateLimiter } from '../../utils/rateLimit'
|
||||
|
||||
const checkIfChatflowIsValidForStreaming = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
@@ -67,7 +67,7 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti
|
||||
`Error: chatflowsRouter.getChatflowByApiKey - apikey not provided!`
|
||||
)
|
||||
}
|
||||
const apikey = await getApiKey(req.params.apikey)
|
||||
const apikey = await apiKeyService.getApiKey(req.params.apikey)
|
||||
if (!apikey) {
|
||||
return res.status(401).send('Unauthorized')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user