fix: prevent preview infinite loop and add document type filtering

- Remove onAutoConfigReceived callback that caused state update loop
- Add document analysis to check if file needs OCR track
- Only show preprocessing options for OCR-eligible files (images, scanned PDFs)
- Show informative message for editable PDFs that use direct text extraction
- Display text coverage percentage for editable documents

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-11-27 17:31:05 +08:00
parent 894d18b432
commit 2861f54838
2 changed files with 76 additions and 39 deletions

View File

@@ -16,7 +16,6 @@ interface PreprocessingPreviewProps {
config: PreprocessingConfig
page?: number
className?: string
onAutoConfigReceived?: (config: PreprocessingConfig) => void
}
export default function PreprocessingPreview({
@@ -25,7 +24,6 @@ export default function PreprocessingPreview({
config,
page = 1,
className,
onAutoConfigReceived,
}: PreprocessingPreviewProps) {
const { t } = useTranslation()
const [isLoading, setIsLoading] = useState(false)
@@ -81,18 +79,13 @@ export default function PreprocessingPreview({
setOriginalImageUrl(URL.createObjectURL(originalBlob))
setPreprocessedImageUrl(URL.createObjectURL(preprocessedBlob))
// Pass auto config to parent if available
if (response.auto_config && onAutoConfigReceived) {
onAutoConfigReceived(response.auto_config)
}
} catch (err: any) {
console.error('Preview fetch error:', err)
setError(err.response?.data?.detail || err.message || 'Failed to load preview')
} finally {
setIsLoading(false)
}
}, [taskId, debouncedMode, debouncedConfig, page, onAutoConfigReceived])
}, [taskId, debouncedMode, debouncedConfig, page])
useEffect(() => {
fetchPreview()