( file: UserFile, options: Base64HydrationOptions, state: HydrationState, logger: Logger )
| 429 | } |
| 430 | |
| 431 | async function hydrateUserFile( |
| 432 | file: UserFile, |
| 433 | options: Base64HydrationOptions, |
| 434 | state: HydrationState, |
| 435 | logger: Logger |
| 436 | ): Promise<UserFile> { |
| 437 | if (!file.base64) { |
| 438 | try { |
| 439 | await assertUserFileContentAccess(file, { |
| 440 | requestId: options.requestId, |
| 441 | workspaceId: options.workspaceId, |
| 442 | workflowId: options.workflowId, |
| 443 | executionId: options.executionId, |
| 444 | largeValueExecutionIds: options.largeValueExecutionIds, |
| 445 | fileKeys: options.fileKeys, |
| 446 | allowLargeValueWorkflowScope: options.allowLargeValueWorkflowScope, |
| 447 | userId: options.userId, |
| 448 | logger, |
| 449 | }) |
| 450 | } catch (error) { |
| 451 | logger.warn(`[${options.requestId ?? 'unknown'}] Skipping unauthorized file base64`, error) |
| 452 | return stripBase64(file) |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | const cached = await state.cache.get(file) |
| 457 | if (cached) { |
| 458 | const maxBytes = options.maxBytes ?? DEFAULT_MAX_BASE64_BYTES |
| 459 | if (Buffer.byteLength(cached, 'base64') > maxBytes) { |
| 460 | return stripBase64(file) |
| 461 | } |
| 462 | return { ...file, base64: cached } |
| 463 | } |
| 464 | |
| 465 | const base64 = await resolveBase64(file, options, logger) |
| 466 | if (!base64) { |
| 467 | return stripBase64(file) |
| 468 | } |
| 469 | |
| 470 | await state.cache.set(file, base64, state.cacheTtlSeconds) |
| 471 | return { ...file, base64 } |
| 472 | } |
| 473 | |
| 474 | async function hydrateValue( |
| 475 | value: unknown, |
no test coverage detected