MCPcopy
hub / github.com/simstudioai/sim / hydrateUserFile

Function hydrateUserFile

apps/sim/lib/uploads/utils/user-file-base64.server.ts:431–472  ·  view source on GitHub ↗
(
  file: UserFile,
  options: Base64HydrationOptions,
  state: HydrationState,
  logger: Logger
)

Source from the content-addressed store, hash-verified

429}
430
431async 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
474async function hydrateValue(
475 value: unknown,

Callers 2

hydrateValueFunction · 0.85

Calls 6

stripBase64Function · 0.85
resolveBase64Function · 0.85
warnMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected