({
componentNodes,
incomingInput,
chatflow,
chatId,
appDataSource,
telemetry,
cachePool,
isInternal,
files,
orgId,
workspaceId,
subscriptionId,
usageCacheManager
}: IExecuteFlowParams)
| 40 | import { validateFlowAPIKey } from './validateKey' |
| 41 | |
| 42 | export const executeUpsert = async ({ |
| 43 | componentNodes, |
| 44 | incomingInput, |
| 45 | chatflow, |
| 46 | chatId, |
| 47 | appDataSource, |
| 48 | telemetry, |
| 49 | cachePool, |
| 50 | isInternal, |
| 51 | files, |
| 52 | orgId, |
| 53 | workspaceId, |
| 54 | subscriptionId, |
| 55 | usageCacheManager |
| 56 | }: IExecuteFlowParams) => { |
| 57 | const question = incomingInput.question |
| 58 | let overrideConfig = incomingInput.overrideConfig ?? {} |
| 59 | let stopNodeId = incomingInput?.stopNodeId ?? '' |
| 60 | const chatHistory: IMessage[] = [] |
| 61 | const isUpsert = true |
| 62 | const chatflowid = chatflow.id |
| 63 | const apiMessageId = uuidv4() |
| 64 | |
| 65 | if (files?.length) { |
| 66 | overrideConfig = { ...incomingInput } |
| 67 | for (const file of files) { |
| 68 | await checkStorage(orgId, subscriptionId, usageCacheManager) |
| 69 | |
| 70 | const fileNames: string[] = [] |
| 71 | const fileBuffer = await getFileFromUpload(file.path ?? file.key) |
| 72 | // Address file name with special characters: https://github.com/expressjs/multer/issues/1104 |
| 73 | file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8') |
| 74 | |
| 75 | // Validate file extension, MIME type, and content to prevent security vulnerabilities |
| 76 | validateFileMimeTypeAndExtensionMatch(file.originalname, file.mimetype) |
| 77 | |
| 78 | const { path: storagePath, totalSize } = await addArrayFilesToStorage( |
| 79 | file.mimetype, |
| 80 | fileBuffer, |
| 81 | file.originalname, |
| 82 | fileNames, |
| 83 | orgId, |
| 84 | chatflowid |
| 85 | ) |
| 86 | await updateStorageUsage(orgId, workspaceId, totalSize, usageCacheManager) |
| 87 | |
| 88 | const fileInputFieldFromMimeType = mapMimeTypeToInputField(file.mimetype) |
| 89 | |
| 90 | const fileExtension = path.extname(file.originalname) |
| 91 | |
| 92 | const fileInputFieldFromExt = mapExtToInputField(fileExtension) |
| 93 | |
| 94 | let fileInputField = 'txtFile' |
| 95 | |
| 96 | if (fileInputFieldFromExt !== 'txtFile') { |
| 97 | fileInputField = fileInputFieldFromExt |
| 98 | } else if (fileInputFieldFromMimeType !== 'txtFile') { |
| 99 | fileInputField = fileInputFieldFromExt |
no test coverage detected