fix the issue

This commit is contained in:
saqib mir
2026-08-22 14:49:06 +05:30
parent 39b125db9a
commit f98d4fa934
2 changed files with 18 additions and 5 deletions
+15 -4
View File
@@ -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<ToolId>();
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);
}
+3 -1
View File
@@ -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();
}