( file: UserFile, options: Base64HydrationOptions, logger: Logger )
| 371 | } |
| 372 | |
| 373 | async function resolveBase64( |
| 374 | file: UserFile, |
| 375 | options: Base64HydrationOptions, |
| 376 | logger: Logger |
| 377 | ): Promise<string | null> { |
| 378 | const maxBytes = options.maxBytes ?? DEFAULT_MAX_BASE64_BYTES |
| 379 | |
| 380 | if (file.base64) { |
| 381 | const base64Bytes = Buffer.byteLength(file.base64, 'base64') |
| 382 | if (base64Bytes > maxBytes) { |
| 383 | logger.warn( |
| 384 | `[${options.requestId}] Skipping existing base64 for ${file.name} (decoded ${base64Bytes} exceeds ${maxBytes})` |
| 385 | ) |
| 386 | return null |
| 387 | } |
| 388 | return file.base64 |
| 389 | } |
| 390 | |
| 391 | const allowUnknownSize = options.allowUnknownSize ?? false |
| 392 | const hasStableStorageKey = Boolean(file.key) |
| 393 | |
| 394 | if (Number.isFinite(file.size) && file.size > maxBytes) { |
| 395 | logger.warn( |
| 396 | `[${options.requestId}] Skipping base64 for ${file.name} (size ${file.size} exceeds ${maxBytes})` |
| 397 | ) |
| 398 | return null |
| 399 | } |
| 400 | |
| 401 | if ( |
| 402 | (!Number.isFinite(file.size) || file.size <= 0) && |
| 403 | !allowUnknownSize && |
| 404 | !hasStableStorageKey |
| 405 | ) { |
| 406 | logger.warn(`[${options.requestId}] Skipping base64 for ${file.name} (unknown file size)`) |
| 407 | return null |
| 408 | } |
| 409 | |
| 410 | const requestId = options.requestId ?? 'unknown' |
| 411 | try { |
| 412 | return await readUserFileContent(file, { |
| 413 | requestId, |
| 414 | workspaceId: options.workspaceId, |
| 415 | workflowId: options.workflowId, |
| 416 | executionId: options.executionId, |
| 417 | largeValueExecutionIds: options.largeValueExecutionIds, |
| 418 | fileKeys: options.fileKeys, |
| 419 | allowLargeValueWorkflowScope: options.allowLargeValueWorkflowScope, |
| 420 | userId: options.userId, |
| 421 | encoding: 'base64', |
| 422 | maxBytes, |
| 423 | maxSourceBytes: maxBytes, |
| 424 | }) |
| 425 | } catch (error) { |
| 426 | logger.warn(`[${requestId}] Failed to hydrate base64 for ${file.name}`, error) |
| 427 | return null |
| 428 | } |
| 429 | } |
| 430 |
no test coverage detected