dorfteich/packages/shared/src/conversion.ts
Claude Opus 4.8 e2f942c0ff
All checks were successful
CD / Build and push images (push) Successful in 3m43s
CI / Lint, typecheck, test (push) Successful in 2m56s
CI / Auth e2e pack (push) Successful in 3m53s
CI / Build container images (push) Has been skipped
CD / Deploy to Test (push) Successful in 10s
CD / Smoke tests against Test (push) Successful in 1m20s
CD / Promote to Int (push) Successful in 11s
Add document import UI in the sidebar (#64)
An "Import document" action in the pond sidebar: pick a .docx/.odt/.md file
(or several), upload with per-file progress, and open the new page. A
.docx/.odt polls the conversion job (queued → converting → done); a .md
imports directly and comes back already succeeded. Failures stay listed with
the localized error and a retry; concurrent imports all complete and appear.

- web apps/web/src/import/: useImport hook (upload via apiUploadFile → poll
  GET /jobs/:id → resolve the page slug → navigate; first success of a batch
  navigates, every success refreshes the sidebar) and ImportControl (hidden
  file input, accept from shared IMPORT_EXTENSIONS, per-file status list).
  Wired into Sidebar next to "new page"; `import` i18n namespace (de+en).
- api: ImportService accepts .md/.markdown and imports in-process (no job),
  returning a succeeded ConversionJobView with the created resultPageId
  ("Markdown imports directly"); the media+parse+create tail is now shared
  between the job path and the sync path (createPageFromMarkdown), and a
  conversion error on the sync path maps to an HTTP status. shared
  IMPORT_EXTENSIONS gains md/markdown.
- e2e apps/web/e2e/import.spec.ts + CI step: .docx corpus fixture opens the
  converted page (self-skips without a reachable pandoc sidecar — CI's e2e
  stack has none, same as #63; verified locally + on stage), .md opens
  directly, an unsupported .txt shows the localized error with no page
  created, and two concurrent .md imports both complete.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
2026-07-10 09:38:31 +02:00

31 lines
1.3 KiB
TypeScript

/**
* Import/export conversion job types shared between api and web (ADR 0009,
* issue #62). A conversion runs asynchronously against the pandoc sidecar;
* the client enqueues it and polls `GET /jobs/:id` for this view.
*/
export type ConversionJobStatus = 'pending' | 'running' | 'succeeded' | 'failed';
export interface ConversionJobView {
id: string;
status: ConversionJobStatus;
kind: string;
sourceFormat: string;
targetFormat: string;
/** Set only when `status` is `failed` — a code from the errors namespace
* (`converter_unavailable` | `converter_timeout` | `conversion_failed` |
* `quota_exceeded`). */
errorCode: string | null;
/** Set once an import job (#63) succeeds: the id of the page it created, so
* the client can navigate to it. `null` for a pending/failed import and for
* plain byte→byte conversions (export). */
resultPageId: string | null;
createdAt: string;
updatedAt: string;
}
/** Extensions the import endpoint accepts (ADR 0009, issues #63/#64). `.docx`
* and `.odt` convert via the sidecar (a job to poll); `.md`/`.markdown` import
* in-process and come back already `succeeded`. */
export const IMPORT_EXTENSIONS = ['docx', 'odt', 'md', 'markdown'] as const;
export type ImportExtension = (typeof IMPORT_EXTENSIONS)[number];