Fix merge conflicts

This commit is contained in:
Ilango
2024-03-11 22:21:25 +05:30
6 changed files with 274 additions and 5 deletions
+30 -1
View File
@@ -1433,7 +1433,36 @@ export class App {
upload.array('files'),
(req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next),
async (req: Request, res: Response) => {
await this.buildChatflow(req, res, socketIO)
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
id: req.params.id
})
if (!chatflow) return res.status(404).send(`Chatflow ${req.params.id} not found`)
let isDomainAllowed = true
logger.info(`[server]: Request originated from ${req.headers.origin}`)
if (chatflow.chatbotConfig) {
const parsedConfig = JSON.parse(chatflow.chatbotConfig)
// check whether the first one is not empty. if it is empty that means the user set a value and then removed it.
const isValidAllowedOrigins = parsedConfig.allowedOrigins?.length && parsedConfig.allowedOrigins[0] !== ''
if (isValidAllowedOrigins) {
const originHeader = req.headers.origin as string
const origin = new URL(originHeader).host
isDomainAllowed =
parsedConfig.allowedOrigins.filter((domain: string) => {
try {
const allowedOrigin = new URL(domain).host
return origin === allowedOrigin
} catch (e) {
return false
}
}).length > 0
}
}
if (isDomainAllowed) {
await this.buildChatflow(req, res, socketIO)
} else {
return res.status(401).send(`This site is not allowed to access this chatbot`)
}
}
)
+4 -3
View File
@@ -493,13 +493,14 @@ export const clearSessionMemory = async (
* @returns {string}
*/
export const getVariableValue = (
paramValue: string,
paramValue: string | object,
reactFlowNodes: IReactFlowNode[],
question: string,
chatHistory: IMessage[],
isAcceptVariable = false
) => {
let returnVal = paramValue
const isObject = typeof paramValue === 'object'
let returnVal = isObject ? JSON.stringify(paramValue) : paramValue
const variableStack = []
const variableDict = {} as IVariableDict
let startIdx = 0
@@ -596,7 +597,7 @@ export const getVariableValue = (
})
return returnVal
}
return returnVal
return isObject ? JSON.parse(returnVal) : returnVal
}
/**