feat: implement Mistral OCR document parsing with fuzzy matching and frontend integration

This commit is contained in:
2025-12-21 11:06:57 +05:30
parent c8b4beafff
commit fc6376abec
13 changed files with 1062 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ export function SourcesPage() {
const [error, setError] = useState<string | null>(null)
const [dragOver, setDragOver] = useState(false)
const [deleteConfirmId, setDeleteConfirmId] = useState<number | null>(null)
const [parsingId, setParsingId] = useState<number | null>(null)
const fileInputRef = useRef<HTMLInputElement>(null)
// Fetch sources on mount
@@ -98,6 +99,31 @@ export function SourcesPage() {
}
}
const handleParse = async (id: number) => {
setParsingId(id)
setError(null)
try {
const res = await fetch(`/api/sources/${id}/parse`, {
method: 'POST',
credentials: 'include',
})
if (res.ok) {
const data = await res.json()
// Refresh sources to show updated status
fetchSources()
console.log('Parsed:', data)
} else {
const err = await res.json()
setError(err.error || 'Parse failed')
}
} catch (e) {
console.error('Failed to parse:', e)
setError('Failed to parse document')
} finally {
setParsingId(null)
}
}
const formatFileSize = (bytes: number) => {
if (bytes < 1024) return `${bytes} B`
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
@@ -196,7 +222,13 @@ export function SourcesPage() {
<img src="/icons/general/icons8-checkmark-50.png" alt="Parsed" className="icon-sm" /> Parsed
</span>
) : (
<span className="text-secondary text-xs">Pending</span>
<button
className="btn btn-primary btn-sm"
onClick={() => handleParse(source.id)}
disabled={parsingId === source.id}
>
{parsingId === source.id ? 'Parsing...' : 'Parse'}
</button>
)}
<button
className="btn btn-danger btn-sm"