docling-studio/frontend/src/features/document/store.ts
Pier-Jean Malandrino fe4e792885 Fix audit findings: remove domain→infra violation, align Serve API, fix DI
- Delete domain/parsing.py (broke hexagonal layering by importing infra)
- Migrate all tests to import directly from domain.value_objects and
  infra.local_converter
- Rewrite ServeConverter to match real Docling Serve v1 API contract:
  options sent as individual form fields (not JSON blob), response
  parsed from document.json_content (DoclingDocument), proper bbox
  coord_origin handling (TOPLEFT/BOTTOMLEFT)
- Transmit all conversion options including generate_picture_images
- Replace fragile lazy import circular dep with FastAPI Depends() +
  app.state for AnalysisService injection
- Add frontend file size validation (50MB) before upload

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 10:58:58 +02:00

65 lines
1.8 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Document } from '../../shared/types'
import * as api from './api'
const MAX_FILE_SIZE = 50 * 1024 * 1024 // 50 MB
export const useDocumentStore = defineStore('document', () => {
const documents = ref<Document[]>([])
const selectedId = ref<string | null>(null)
const uploading = ref(false)
const error = ref<string | null>(null)
function clearError(): void {
error.value = null
}
async function load(): Promise<void> {
try {
error.value = null
documents.value = await api.fetchDocuments()
} catch (e) {
error.value = (e as Error).message || 'Failed to load documents'
console.error('Failed to load documents', e)
}
}
async function upload(file: File): Promise<Document> {
if (file.size > MAX_FILE_SIZE) {
error.value = 'File too large (max 50 MB)'
throw new Error(error.value)
}
uploading.value = true
error.value = null
try {
const doc = await api.uploadDocument(file)
documents.value.unshift(doc)
selectedId.value = doc.id
return doc
} catch (e) {
error.value = (e as Error).message || 'Failed to upload document'
console.error('Failed to upload document', e)
throw e
} finally {
uploading.value = false
}
}
async function remove(id: string): Promise<void> {
try {
await api.deleteDocument(id)
documents.value = documents.value.filter((d) => d.id !== id)
if (selectedId.value === id) selectedId.value = null
} catch (e) {
error.value = (e as Error).message || 'Failed to delete document'
console.error('Failed to delete document', e)
}
}
function select(id: string): void {
selectedId.value = id
}
return { documents, selectedId, uploading, error, clearError, load, upload, remove, select }
})