docling-studio/frontend/src/features/document/api.ts
Pier-Jean Malandrino b4ad874600 fix(#256): drop pushDocumentToStore duplicate, align rechunk return shape
The frontend had two endpoints pointing at the same operation:
  - features/document/api.ts:pushDocumentToStore  → POST /push
  - features/chunks/api.ts:pushChunksToStore      → POST /chunks/push

Backend now exposes a single /chunks/push route (semantically more
accurate — it's chunks that get pushed, not the doc itself), so the
document-side variant is removed. document/store.ts:pushToStore now
delegates to chunks/api.

rechunkDocument returned {jobId} based on the old async-job model.
The new backend rechunk runs synchronously and returns the chunk
list directly. The DocsLibraryPage caller now reports a count
(via new docs.rechunkDone i18n key) instead of a fake job id.

Adds data-e2e=tab-{mode} on the doc workspace tab strip so the
new Karate scenario can target the chunks tab without text matching.

Extends chunks/api.test.ts with HTTP error-propagation guards on
every call — the original 404 bug would have surfaced in CI.
2026-05-11 15:00:57 +02:00

41 lines
1.3 KiB
TypeScript

import type { DocChunk, Document, DocTreeNode } from '../../shared/types'
import { apiFetch } from '../../shared/api/http'
export function fetchDocuments(): Promise<Document[]> {
return apiFetch<Document[]>('/api/documents')
}
export function fetchDocument(id: string): Promise<Document> {
return apiFetch<Document>(`/api/documents/${id}`)
}
export async function uploadDocument(file: File): Promise<Document> {
const formData = new FormData()
formData.append('file', file)
return apiFetch<Document>('/api/documents/upload', {
method: 'POST',
body: formData,
skipContentType: true,
})
}
export function deleteDocument(id: string): Promise<unknown> {
return apiFetch(`/api/documents/${id}`, { method: 'DELETE' })
}
export function getPreviewUrl(id: string, page = 1, dpi = 150): string {
return `/api/documents/${id}/preview?page=${page}&dpi=${dpi}`
}
/** Rechunk the canonical chunkset. Backend runs synchronously and returns
* the new chunks — there is no async job to poll. */
export function rechunkDocument(id: string): Promise<DocChunk[]> {
return apiFetch<DocChunk[]>(`/api/documents/${id}/rechunk`, {
method: 'POST',
body: JSON.stringify({}),
})
}
export function fetchDocumentTree(id: string): Promise<DocTreeNode[]> {
return apiFetch<DocTreeNode[]>(`/api/documents/${id}/tree`)
}