(
fileParam: unknown,
options?: { single?: boolean; errorMessage?: string }
)
| 572 | options?: { single?: false } |
| 573 | ): object[] | undefined |
| 574 | export function normalizeFileInput( |
| 575 | fileParam: unknown, |
| 576 | options?: { single?: boolean; errorMessage?: string } |
| 577 | ): object | object[] | undefined { |
| 578 | if (!fileParam) return undefined |
| 579 | |
| 580 | if (typeof fileParam === 'string') { |
| 581 | try { |
| 582 | fileParam = JSON.parse(fileParam) |
| 583 | } catch { |
| 584 | return undefined |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | let files: object[] | undefined |
| 589 | |
| 590 | if (Array.isArray(fileParam)) { |
| 591 | files = fileParam.length > 0 ? fileParam : undefined |
| 592 | } else if (typeof fileParam === 'object' && fileParam !== null) { |
| 593 | files = [fileParam] |
| 594 | } |
| 595 | |
| 596 | if (!files) return undefined |
| 597 | |
| 598 | if (options?.single) { |
| 599 | if (files.length > 1) { |
| 600 | throw new Error(options.errorMessage ?? DEFAULT_MULTIPLE_FILES_ERROR) |
| 601 | } |
| 602 | return files[0] |
| 603 | } |
| 604 | |
| 605 | return files |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Block types that are built-in to the platform (as opposed to third-party integrations). |
no test coverage detected