* Parse a single file and return its content
( filePath: string, fileType: string, workspaceId: string, userId: string, executionContext?: ExecutionContext, headers?: Record<string, string>, signal?: AbortSignal, maxDownloadBytes = MAX_DOWNLOAD_SIZE_BYTES, maxParsedOutputBytes?: number )
| 261 | * Parse a single file and return its content |
| 262 | */ |
| 263 | async function parseFileSingle( |
| 264 | filePath: string, |
| 265 | fileType: string, |
| 266 | workspaceId: string, |
| 267 | userId: string, |
| 268 | executionContext?: ExecutionContext, |
| 269 | headers?: Record<string, string>, |
| 270 | signal?: AbortSignal, |
| 271 | maxDownloadBytes = MAX_DOWNLOAD_SIZE_BYTES, |
| 272 | maxParsedOutputBytes?: number |
| 273 | ): Promise<ParseResult> { |
| 274 | logger.info('Parsing file:', filePath) |
| 275 | |
| 276 | if (!filePath || filePath.trim() === '') { |
| 277 | return { |
| 278 | success: false, |
| 279 | error: 'Empty file path provided', |
| 280 | filePath: filePath || '', |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | const referenceValidation = validateFileReferenceShape(filePath) |
| 285 | if (!referenceValidation.isValid) { |
| 286 | return { |
| 287 | success: false, |
| 288 | error: referenceValidation.error || 'Invalid file reference', |
| 289 | filePath, |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | const pathValidation = validateFilePath(filePath) |
| 294 | if (!pathValidation.isValid) { |
| 295 | return { |
| 296 | success: false, |
| 297 | error: pathValidation.error || 'Invalid path', |
| 298 | filePath, |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | if (isInternalFileUrl(filePath)) { |
| 303 | return handleCloudFile( |
| 304 | filePath, |
| 305 | fileType, |
| 306 | undefined, |
| 307 | userId, |
| 308 | executionContext, |
| 309 | maxDownloadBytes, |
| 310 | maxParsedOutputBytes |
| 311 | ) |
| 312 | } |
| 313 | |
| 314 | if (filePath.startsWith('http://') || filePath.startsWith('https://')) { |
| 315 | return handleExternalUrl( |
| 316 | filePath, |
| 317 | fileType, |
| 318 | workspaceId, |
| 319 | userId, |
| 320 | executionContext, |
no test coverage detected