Fix apikey not URL safe (#2602)
This commit is contained in:
parent
c34eb8ee15
commit
371e632a2c
|
|
@ -71,7 +71,7 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti
|
||||||
if (!apikey) {
|
if (!apikey) {
|
||||||
return res.status(401).send('Unauthorized')
|
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)
|
return res.json(apiResponse)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error)
|
next(error)
|
||||||
|
|
|
||||||
|
|
@ -120,17 +120,18 @@ const getAllChatflows = async (type?: ChatflowType): Promise<IChatFlow[]> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getChatflowByApiKey = async (apiKeyId: string): Promise<any> => {
|
const getChatflowByApiKey = async (apiKeyId: string, keyonly?: unknown): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
// Here we only get chatflows that are bounded by the apikeyid and chatflows that are not bounded by any apikey
|
// Here we only get chatflows that are bounded by the apikeyid and chatflows that are not bounded by any apikey
|
||||||
const appServer = getRunningExpressApp()
|
const appServer = getRunningExpressApp()
|
||||||
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow)
|
let query = appServer.AppDataSource.getRepository(ChatFlow)
|
||||||
.createQueryBuilder('cf')
|
.createQueryBuilder('cf')
|
||||||
.where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId })
|
.where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId })
|
||||||
.orWhere('cf.apikeyid IS NULL')
|
if (keyonly === undefined) {
|
||||||
.orWhere('cf.apikeyid = ""')
|
query = query.orWhere('cf.apikeyid IS NULL').orWhere('cf.apikeyid = ""')
|
||||||
.orderBy('cf.name', 'ASC')
|
}
|
||||||
.getMany()
|
|
||||||
|
const dbResponse = await query.orderBy('cf.name', 'ASC').getMany()
|
||||||
if (dbResponse.length < 1) {
|
if (dbResponse.length < 1) {
|
||||||
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
|
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const getAPIKeyPath = (): string => {
|
||||||
*/
|
*/
|
||||||
export const generateAPIKey = (): string => {
|
export const generateAPIKey = (): string => {
|
||||||
const buffer = randomBytes(32)
|
const buffer = randomBytes(32)
|
||||||
return buffer.toString('base64')
|
return buffer.toString('base64url')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue