From 5f10a8b82ca682df34d8f2d07714f4360a451fde Mon Sep 17 00:00:00 2001 From: perf3ct Date: Sun, 29 Jun 2025 23:27:51 +0000 Subject: [PATCH] feat(server): continue to try to wrangle the failed and ignored documents --- .../src/components/FailedDocumentViewer.tsx | 152 +++ frontend/src/pages/DocumentManagementPage.tsx | 882 +++++++++++++----- .../__tests__/DocumentManagementPage.tsx | 4 +- src/db/documents.rs | 98 ++ src/ingestion/document_ingestion.rs | 68 +- src/ocr/queue.rs | 134 ++- src/routes/documents.rs | 72 ++ 7 files changed, 1142 insertions(+), 268 deletions(-) create mode 100644 frontend/src/components/FailedDocumentViewer.tsx diff --git a/frontend/src/components/FailedDocumentViewer.tsx b/frontend/src/components/FailedDocumentViewer.tsx new file mode 100644 index 0000000..8b7b0fb --- /dev/null +++ b/frontend/src/components/FailedDocumentViewer.tsx @@ -0,0 +1,152 @@ +import React, { useState, useEffect } from 'react'; +import { + Box, + Typography, + CircularProgress, + Alert, + Paper, +} from '@mui/material'; +import { api } from '../services/api'; + +interface FailedDocumentViewerProps { + failedDocumentId: string; + filename: string; + mimeType: string; +} + +const FailedDocumentViewer: React.FC = ({ + failedDocumentId, + filename, + mimeType, +}) => { + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [documentUrl, setDocumentUrl] = useState(null); + + useEffect(() => { + loadFailedDocument(); + + // Cleanup URL when component unmounts + return () => { + if (documentUrl) { + window.URL.revokeObjectURL(documentUrl); + } + }; + }, [failedDocumentId]); + + const loadFailedDocument = async (): Promise => { + try { + setLoading(true); + setError(null); + + // Use the new failed document view endpoint + const response = await api.get(`/documents/failed/${failedDocumentId}/view`, { + responseType: 'blob' + }); + + const url = window.URL.createObjectURL(new Blob([response.data], { type: mimeType })); + setDocumentUrl(url); + } catch (err: any) { + console.error('Failed to load failed document:', err); + if (err.response?.status === 404) { + setError('Document file not found or has been deleted'); + } else { + setError('Failed to load document for viewing'); + } + } finally { + setLoading(false); + } + }; + + if (loading) { + return ( + + + + ); + } + + if (error) { + return ( + + {error} + + The original file may have been deleted or moved from storage. + + + ); + } + + return ( + + {documentUrl && ( + <> + {mimeType.startsWith('image/') ? ( + + {filename} + + ) : mimeType === 'application/pdf' ? ( +