mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
API Keys: Displaying the names of the chatflows associated with the keys and Warning the user before deletion.
This commit is contained in:
@@ -1135,28 +1135,50 @@ export class App {
|
||||
// API Keys
|
||||
// ----------------------------------------
|
||||
|
||||
const addChatflowsCount = async (keys: any, res: Response) => {
|
||||
if (keys) {
|
||||
const updatedKeys: any[] = []
|
||||
//iterate through keys and get chatflows
|
||||
for (const key of keys) {
|
||||
const chatflows = await this.AppDataSource.getRepository(ChatFlow)
|
||||
.createQueryBuilder('cf')
|
||||
.where('cf.apikeyid = :apikeyid', { apikeyid: key.id })
|
||||
.getMany()
|
||||
const linkedChatFlows: any[] = []
|
||||
chatflows.map((cf) => {
|
||||
linkedChatFlows.push({
|
||||
flowName: cf.name
|
||||
})
|
||||
})
|
||||
key.chatFlows = linkedChatFlows
|
||||
updatedKeys.push(key)
|
||||
}
|
||||
return res.json(updatedKeys)
|
||||
}
|
||||
return res.json(keys)
|
||||
}
|
||||
// Get api keys
|
||||
this.app.get('/api/v1/apikey', async (req: Request, res: Response) => {
|
||||
const keys = await getAPIKeys()
|
||||
return res.json(keys)
|
||||
return addChatflowsCount(keys, res)
|
||||
})
|
||||
|
||||
// Add new api key
|
||||
this.app.post('/api/v1/apikey', async (req: Request, res: Response) => {
|
||||
const keys = await addAPIKey(req.body.keyName)
|
||||
return res.json(keys)
|
||||
return addChatflowsCount(keys, res)
|
||||
})
|
||||
|
||||
// Update api key
|
||||
this.app.put('/api/v1/apikey/:id', async (req: Request, res: Response) => {
|
||||
const keys = await updateAPIKey(req.params.id, req.body.keyName)
|
||||
return res.json(keys)
|
||||
return addChatflowsCount(keys, res)
|
||||
})
|
||||
|
||||
// Delete new api key
|
||||
this.app.delete('/api/v1/apikey/:id', async (req: Request, res: Response) => {
|
||||
const keys = await deleteAPIKey(req.params.id)
|
||||
return res.json(keys)
|
||||
return addChatflowsCount(keys, res)
|
||||
})
|
||||
|
||||
// Verify api key
|
||||
|
||||
Reference in New Issue
Block a user