Fix merge conflicts

This commit is contained in:
Ilango
2024-03-05 17:01:08 +05:30
4 changed files with 202 additions and 2 deletions
+22 -1
View File
@@ -1319,7 +1319,28 @@ 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[0] !== ''
if (parsedConfig.allowedOrigins && parsedConfig.allowedOrigins.length > 0 && isValidAllowedOrigins) {
const originHeader = req.headers.origin as string
const origin = new URL(originHeader).host
isDomainAllowed = parsedConfig.allowedOrigins.includes(origin)
}
}
if (isDomainAllowed) {
await this.buildChatflow(req, res, socketIO)
} else {
return res.status(401).send(`This site is not allowed to access this chatbot`)
}
}
)