(
input: unknown,
blocks: SerializedBlock[],
executionContext: { workspaceId: string; workflowId: string; executionId: string },
requestId: string,
userId?: string
)
| 144 | * This handles base64 and URL file inputs from API calls |
| 145 | */ |
| 146 | export async function processInputFileFields( |
| 147 | input: unknown, |
| 148 | blocks: SerializedBlock[], |
| 149 | executionContext: { workspaceId: string; workflowId: string; executionId: string }, |
| 150 | requestId: string, |
| 151 | userId?: string |
| 152 | ): Promise<unknown> { |
| 153 | if (!input || typeof input !== 'object' || blocks.length === 0) { |
| 154 | return input |
| 155 | } |
| 156 | |
| 157 | const startBlock = blocks.find((block) => { |
| 158 | const blockType = block.metadata?.id |
| 159 | return ( |
| 160 | blockType === TRIGGER_TYPES.START || |
| 161 | blockType === TRIGGER_TYPES.API || |
| 162 | blockType === TRIGGER_TYPES.INPUT || |
| 163 | blockType === TRIGGER_TYPES.GENERIC_WEBHOOK || |
| 164 | blockType === TRIGGER_TYPES.STARTER |
| 165 | ) |
| 166 | }) |
| 167 | |
| 168 | if (!startBlock) { |
| 169 | return input |
| 170 | } |
| 171 | |
| 172 | const inputFormat = extractInputFormatFromBlock(startBlock) |
| 173 | const fileFields = inputFormat.filter((field) => field.type === 'file[]') |
| 174 | |
| 175 | if (fileFields.length === 0) { |
| 176 | return input |
| 177 | } |
| 178 | |
| 179 | const processedInput = { ...input } as Record<string, unknown> |
| 180 | |
| 181 | for (const fileField of fileFields) { |
| 182 | const fieldValue = processedInput[fileField.name] |
| 183 | |
| 184 | if (fieldValue && typeof fieldValue === 'object') { |
| 185 | const uploadedFiles = await processExecutionFiles( |
| 186 | fieldValue, |
| 187 | executionContext, |
| 188 | requestId, |
| 189 | userId |
| 190 | ) |
| 191 | |
| 192 | if (uploadedFiles.length > 0) { |
| 193 | processedInput[fileField.name] = uploadedFiles |
| 194 | logger.info( |
| 195 | `[${requestId}] Successfully processed ${uploadedFiles.length} file(s) for field: ${fileField.name}` |
| 196 | ) |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return processedInput |
| 202 | } |
no test coverage detected