Skip to Content
⚠️Active Development Notice: TimeTiles is under active development. Information may be placeholder content or not up-to-date.

web


web / app/api/ingest/preview-schema/helpers

app/api/ingest/preview-schema/helpers

Shared helpers for preview-schema endpoints (upload and URL).

Contains file parsing, field detection, and URL validation logic used by both the upload and URL preview routes. Preview storage operations (path creation, metadata save/load, cleanup) are delegated to @/lib/ingest/preview-store.

Variables

ALLOWED_MIME_TYPES

const ALLOWED_MIME_TYPES: string[]


MAX_FILE_SIZE

const MAX_FILE_SIZE: number


SAMPLE_ROW_COUNT

const SAMPLE_ROW_COUNT: 5 = 5


FILE_EXTENSION_REGEX

const FILE_EXTENSION_REGEX: RegExp

Functions

detectSuggestedMappings()

detectSuggestedMappings(headers, sampleData): SuggestedMappings

Detect suggested field mappings for a sheet

Parameters

headers

string[]

sampleData

Record<string, unknown>[]

Returns

SuggestedMappings


parseCSVPreview()

parseCSVPreview(filePath): SheetInfo[]

Parameters

filePath

string

Returns

SheetInfo[]


parseExcelPreview()

parseExcelPreview(filePath): SheetInfo[]

Parameters

filePath

string

Returns

SheetInfo[]


parseFileSheets()

parseFileSheets(filePath, fileExtension): SheetInfo[]

Parse file sheets based on file extension.

Parameters

filePath

string

fileExtension

string

Returns

SheetInfo[]


findConfigSuggestionsForUser()

findConfigSuggestionsForUser(payload, userId, headers): Promise<ConfigSuggestion[]>

Query the user’s datasets and find config suggestions matching the given headers.

Fetches datasets owned by the user (via catalog.createdBy) and delegates matching to the pure findConfigSuggestions function.

Parameters

payload

BasePayload

userId

number

headers

string[]

Returns

Promise<ConfigSuggestion[]>


buildPreviewResult()

buildPreviewResult(__namedParameters): Promise<{ sheets: [SheetInfo](../../../../lib/types/ingest-wizard.md#sheetinfo)[]; configSuggestions: [ConfigSuggestion](../../../../lib/types/ingest-wizard.md#configsuggestion)[]; }>

Shared pipeline for both upload and URL preview routes.

Parses the saved file, stores metadata, finds config suggestions, and returns sheets with suggestions. Cleans up the file on parse errors.

Parameters

__namedParameters

BuildPreviewResultParams

Returns

Promise<{ sheets: [SheetInfo](../../../../lib/types/ingest-wizard.md#sheetinfo)[]; configSuggestions: [ConfigSuggestion](../../../../lib/types/ingest-wizard.md#configsuggestion)[]; }>


getPreviewDir()

getPreviewDir(): string

Get (and lazily create) the preview temp directory. Use this for write operations that need the directory to exist.

Returns

string


savePreviewMetadata()

savePreviewMetadata(opts): void

Save preview metadata to disk. Intentionally omits authConfig to avoid persisting secrets to disk.

Parameters

opts

SavePreviewMetadataOpts

Returns

void


validateUrl()

validateUrl(urlString): { url: URL; } | { error: string; }

Validates that a string is a valid external HTTP(S) URL.

Rejects non-HTTP protocols and private/internal addresses (SSRF protection). Returns the parsed URL on success or an error message on failure.

Parameters

urlString

string

Returns

{ url: URL; } | { error: string; }

References

AuthConfig

Re-exports AuthConfig


SheetInfo

Re-exports SheetInfo


SuggestedMappings

Re-exports SuggestedMappings

Last updated on