Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript
2.9 KB
Raw Blame
export type DoResumableDownloadParams = {
  url: string
  filepath: string
  timeout: number
  allowedMimeTypes: string[]
  signal?: AbortSignal
  onProgress?: (progress: DoResumableDownloadProgress) => void
  onComplete?: (url: string, path: string) => void | Promise<void>
  forceNew?: boolean
  /**
   * Extra HTTP request headers sent on BOTH the HEAD probe and the GET stream.
   * Used by Creator Packs to carry the `Authorization: Bearer <APP_KEY>` the
   * entitlement Worker requires; the Range header still composes on top for
   * resumed downloads. Kept generic so any gated source can reuse it.
   */
  requestHeaders?: Record<string, string>
}

export type DoResumableDownloadWithRetryParams = DoResumableDownloadParams & {
  max_retries?: number
  retry_delay?: number
  onAttemptError?: (error: Error, attempt: number) => void
}

export type DoResumableDownloadProgress = {
  downloadedBytes: number
  totalBytes: number
  lastProgressTime: number
  lastDownloadedBytes: number
  url: string
}

export type DownloadProgressData = {
  percent: number
  downloadedBytes: number
  totalBytes: number
  lastProgressTime: number
}

export type RunDownloadJobParams = Omit<
  DoResumableDownloadParams,
  'onProgress' | 'onComplete' | 'signal'
> & {
  filetype: string
  title?: string
  totalBytes?: number
  resourceMetadata?: {
    resource_id: string
    version: string
    collection_ref: string | null
    /**
     * True only when this download was initiated by the content auto-updater.
     * Gates the per-resource auto-update backoff (success reset in
     * RunDownloadJob.onComplete, terminal-failure increment in the worker
     * `failed` handler) so manual downloads never touch the counter.
     */
    auto?: boolean
    /**
     * Skip the RAG/knowledge-base ingestion branch in RunDownloadJob.onComplete.
     * Set for video ZIMs (Creator Packs) — they are media galleries, not text,
     * and must never be dispatched to EmbedFileJob or the replacement-reconcile
     * path. The Kiwix rebuild still runs so the pack appears in the grid.
     */
    skip_embedding?: boolean
  }
}

export type DownloadJobWithProgress = {
  jobId: string
  url: string
  progress: number
  filepath: string
  filetype: string
  title?: string
  downloadedBytes?: number
  totalBytes?: number
  lastProgressTime?: number
  status?: 'active' | 'waiting' | 'delayed' | 'failed'
  failedReason?: string
}

// Wikipedia selector types
export type WikipediaOption = {
  id: string
  name: string
  description: string
  size_mb: number
  url: string | null
}

export type WikipediaOptionsFile = {
  options: WikipediaOption[]
}

export type WikipediaCurrentSelection = {
  optionId: string
  status: 'none' | 'downloading' | 'installed' | 'failed'
  filename: string | null
  url: string | null
}

export type WikipediaState = {
  options: WikipediaOption[]
  currentSelection: WikipediaCurrentSelection | null
}