From f98d4fa934271e3f5d19e82c602b286c1f113176 Mon Sep 17 00:00:00 2001 From: saqib mir Date: Sat, 22 Aug 2026 14:49:06 +0530 Subject: [PATCH] fix the issue --- frontend/src/App.tsx | 19 +++++++++++++++---- frontend/src/lib/gatewayService.ts | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 9a22900..9148670 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -52,13 +52,20 @@ function App() { const canRedo = hist.index < hist.stack.length - 1; const preservePageRef = useRef(false); + const [isOcrDisabled, setIsOcrDisabled] = useState(false); const permissions = activeDoc?.permissions ?? null; const can = (flag: keyof PDFPermissions) => !permissions || permissions[flag] !== false; const denyToast = (_label: string) => { }; const disabledTools = new Set(); - if (!can('canAnnotate')) - (['highlight', 'underline', 'strikeout', 'squiggly', 'draw', 'comment', 'textbox', 'stamp', 'signature'] as ToolId[]).forEach((t) => disabledTools.add(t)); - if (!can('canModify')) (['edit_text', 'redact'] as ToolId[]).forEach((t) => disabledTools.add(t)); + disabledTools.add('ocr'); // OCR & Edit button is permanently disabled + if (!activeDoc) { + (['highlight', 'underline', 'strikeout', 'squiggly', 'draw', 'comment', 'textbox', 'edit_text', 'stream_edit', 'signature', 'stamp', 'watermark', 'redact'] as ToolId[]).forEach((t) => disabledTools.add(t)); + } else { + if (!can('canAnnotate')) + (['highlight', 'underline', 'strikeout', 'squiggly', 'draw', 'comment', 'textbox', 'stamp', 'signature'] as ToolId[]).forEach((t) => disabledTools.add(t)); + if (!can('canModify')) + (['edit_text', 'stream_edit', 'redact'] as ToolId[]).forEach((t) => disabledTools.add(t)); + } const disabledToolsRef = useRef(disabledTools); disabledToolsRef.current = disabledTools; @@ -153,7 +160,11 @@ function App() { await gatewayService.performPageOCR(activeDoc.id, currentPage); viewerRef.current?.refreshPageLayout(currentPage); } catch (err: any) { - alert(`OCR processing failed: ${err.message || err}`); + const errMsg = err.message || String(err); + alert(`OCR processing failed: ${errMsg}`); + if (errMsg.toLowerCase().includes('not installed') || errMsg.toLowerCase().includes('not available')) { + setIsOcrDisabled(true); + } } finally { setIsOCRLoading(false); } diff --git a/frontend/src/lib/gatewayService.ts b/frontend/src/lib/gatewayService.ts index 9bc86fa..5642e0b 100644 --- a/frontend/src/lib/gatewayService.ts +++ b/frontend/src/lib/gatewayService.ts @@ -727,7 +727,9 @@ class GatewayService { method: 'POST', }); if (!response.ok) { - throw new Error(`OCR failed: ${response.statusText}`); + const errJson = await response.json().catch(() => null); + const detail = errJson?.detail || response.statusText; + throw new Error(detail); } return response.json(); }