feat: refactor dual-track architecture (Phase 1-5)

## Backend Changes
- **Service Layer Refactoring**:
  - Add ProcessingOrchestrator for unified document processing
  - Add PDFTableRenderer for table rendering extraction
  - Add PDFFontManager for font management with CJK support
  - Add MemoryPolicyEngine (73% code reduction from MemoryGuard)

- **Bug Fixes**:
  - Fix Direct Track table row span calculation
  - Fix OCR Track image path handling
  - Add cell_boxes coordinate validation
  - Filter out small decorative images
  - Add covering image detection

## Frontend Changes
- **State Management**:
  - Add TaskStore for centralized task state management
  - Add localStorage persistence for recent tasks
  - Add processing state tracking

- **Type Consolidation**:
  - Merge shared types from api.ts to apiV2.ts
  - Update imports in authStore, uploadStore, ResultsTable, SettingsPage

- **Page Integration**:
  - Integrate TaskStore in ProcessingPage and TaskDetailPage
  - Update useTaskValidation hook with cache sync

## Testing
- Direct Track: edit.pdf (3 pages, 1.281s), edit3.pdf (2 pages, 0.203s)
- Cell boxes validation: 43 valid, 0 invalid
- Table merging: 12 merged cells verified

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-07 07:18:27 +08:00
parent 8265be1741
commit eff9b0bcd5
19 changed files with 3637 additions and 173 deletions

View File

@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useUploadStore } from '@/store/uploadStore'
import { useTaskStore } from '@/store/taskStore'
import { apiClientV2 } from '@/services/apiV2'
import type { TaskDetail } from '@/types/apiV2'
@@ -15,13 +16,21 @@ interface UseTaskValidationResult {
/**
* Hook for validating task existence and handling deleted tasks gracefully.
* Shows loading state first, then either returns task data or marks as not found.
*
* This hook integrates with both uploadStore (legacy) and taskStore (new).
* The taskId is sourced from uploadStore.batchId for backward compatibility,
* while task metadata is synced to taskStore for caching and state management.
*/
export function useTaskValidation(options?: {
refetchInterval?: number | false | ((query: any) => number | false)
}): UseTaskValidationResult {
// Legacy: Get taskId from uploadStore
const { batchId, clearUpload } = useUploadStore()
const taskId = batchId ? String(batchId) : null
// New: Use taskStore for caching and state management
const { updateTaskCache, removeFromCache, clearCurrentTask } = useTaskStore()
const [isNotFound, setIsNotFound] = useState(false)
const { data: taskDetail, isLoading, error, isFetching } = useQuery({
@@ -40,16 +49,27 @@ export function useTaskValidation(options?: {
staleTime: 0,
})
// Handle 404 error - mark as not found immediately
// Sync task details to taskStore cache when data changes
useEffect(() => {
if (taskDetail) {
updateTaskCache(taskDetail)
}
}, [taskDetail, updateTaskCache])
// Handle 404 error - mark as not found and clean up cache
useEffect(() => {
if (error && (error as any)?.response?.status === 404) {
setIsNotFound(true)
if (taskId) {
removeFromCache(taskId)
}
}
}, [error])
}, [error, taskId, removeFromCache])
// Clear state and store
const clearAndReset = () => {
clearUpload()
clearUpload() // Legacy store
clearCurrentTask() // New store
setIsNotFound(false)
}