diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts index dc86090a0..f6e903188 100644 --- a/packages/server/src/controllers/chatflows/index.ts +++ b/packages/server/src/controllers/chatflows/index.ts @@ -71,7 +71,7 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti if (!apikey) { return res.status(401).send('Unauthorized') } - const apiResponse = await chatflowsService.getChatflowByApiKey(apikey.id) + const apiResponse = await chatflowsService.getChatflowByApiKey(apikey.id, req.query.keyonly) return res.json(apiResponse) } catch (error) { next(error) diff --git a/packages/server/src/services/chatflows/index.ts b/packages/server/src/services/chatflows/index.ts index 63a33475c..e68e02b95 100644 --- a/packages/server/src/services/chatflows/index.ts +++ b/packages/server/src/services/chatflows/index.ts @@ -120,17 +120,18 @@ const getAllChatflows = async (type?: ChatflowType): Promise => { } } -const getChatflowByApiKey = async (apiKeyId: string): Promise => { +const getChatflowByApiKey = async (apiKeyId: string, keyonly?: unknown): Promise => { try { // Here we only get chatflows that are bounded by the apikeyid and chatflows that are not bounded by any apikey const appServer = getRunningExpressApp() - const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow) + let query = appServer.AppDataSource.getRepository(ChatFlow) .createQueryBuilder('cf') .where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId }) - .orWhere('cf.apikeyid IS NULL') - .orWhere('cf.apikeyid = ""') - .orderBy('cf.name', 'ASC') - .getMany() + if (keyonly === undefined) { + query = query.orWhere('cf.apikeyid IS NULL').orWhere('cf.apikeyid = ""') + } + + const dbResponse = await query.orderBy('cf.name', 'ASC').getMany() if (dbResponse.length < 1) { throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`) } diff --git a/packages/server/src/utils/apiKey.ts b/packages/server/src/utils/apiKey.ts index 08a9ecd37..57239825b 100644 --- a/packages/server/src/utils/apiKey.ts +++ b/packages/server/src/utils/apiKey.ts @@ -19,7 +19,7 @@ export const getAPIKeyPath = (): string => { */ export const generateAPIKey = (): string => { const buffer = randomBytes(32) - return buffer.toString('base64') + return buffer.toString('base64url') } /**