Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Feat: optimize the information displayed when .doc preview is unavailable (#11684)

Billy Bao6fc7def56237
diff --git a/common/misc_utils.py b/common/misc_utils.py
index daebf4c8cd..694b8b494e 100644
--- a/common/misc_utils.py
+++ b/common/misc_utils.py
@@ -173,8 +173,8 @@ def install_mineru() -> None:
Logging is used to indicate status.
"""
# Check if MinerU is enabled
- use_mineru = os.getenv("USE_MINERU", "").strip().lower()
- if use_mineru == "false":
+ use_mineru = os.getenv("USE_MINERU", "false").strip().lower()
+ if use_mineru != "true":
logging.info("USE_MINERU=%r. Skipping MinerU installation.", use_mineru)
return
diff --git a/web/src/components/document-preview/doc-preview.tsx b/web/src/components/document-preview/doc-preview.tsx
index 470765f6ee..5f8dd0cf92 100644
--- a/web/src/components/document-preview/doc-preview.tsx
+++ b/web/src/components/document-preview/doc-preview.tsx
@@ -1,7 +1,5 @@
import message from '@/components/ui/message';
import { Spin } from '@/components/ui/spin';
-import { Authorization } from '@/constants/authorization';
-import { getAuthorization } from '@/utils/authorization-util';
import request from '@/utils/request';
import classNames from 'classnames';
import mammoth from 'mammoth';
@@ -16,22 +14,55 @@ export const DocPreviewer: React.FC<DocPreviewerProps> = ({
className,
url,
}) => {
- // const url = useGetDocumentUrl();
const [htmlContent, setHtmlContent] = useState<string>('');
const [loading, setLoading] = useState(false);
+
const fetchDocument = async () => {
+ if (!url) return;
+
setLoading(true);
+
const res = await request(url, {
method: 'GET',
responseType: 'blob',
- headers: { [Authorization]: getAuthorization() },
onError: () => {
message.error('Document parsing failed');
console.error('Error loading document:', url);
},
});
+
try {
- const arrayBuffer = await res.data.arrayBuffer();
+ const blob: Blob = res.data;
+ const contentType: string =
+ blob.type || (res as any).headers?.['content-type'] || '';
+
+ // ---- Detect legacy .doc via MIME or URL ----
+ const cleanUrl = url.split(/[?#]/)[0].toLowerCase();
+ const isDocMime = /application\/msword/i.test(contentType);
+ const isLegacyDocByUrl =
+ cleanUrl.endsWith('.doc') && !cleanUrl.endsWith('.docx');
+ const isLegacyDoc = isDocMime || isLegacyDocByUrl;
+
+ if (isLegacyDoc) {
+ // Do not call mammoth and do not throw an error; instead, show a note in the preview area
+ setHtmlContent(`
+ <div class="flex h-full items-center justify-center">
+ <div class="border border-dashed border-border-normal rounded-xl p-8 max-w-2xl text-center">
+ <p class="text-2xl font-bold mb-4">
+ Preview not available for .doc files
+ </p>
+ <p class="italic text-sm text-muted-foreground leading-relaxed">
+ Mammoth does not support <code>.doc</code> documents.<br/>
+ Inline preview is unavailable.
+ </p>
+ </div>
+ </div>
+ `);
+ return;
+ }
+
+ // ---- Standard .docx preview path ----
+ const arrayBuffer = await blob.arrayBuffer();
const result = await mammoth.convertToHtml(
{ arrayBuffer },
{ includeDefaultStyleMap: true },
@@ -43,10 +74,12 @@ export const DocPreviewer: React.FC<DocPreviewerProps> = ({
setHtmlContent(styledContent);
} catch (err) {
+ // Only errors from the mammoth conversion path should surface here
message.error('Document parsing failed');
console.error('Error parsing document:', err);
+ } finally {
+ setLoading(false);
}
- setLoading(false);
};
useEffect(() => {
@@ -54,6 +87,7 @@ export const DocPreviewer: React.FC<DocPreviewerProps> = ({
fetchDocument();
}
}, [url]);
+
return (
<div
className={classNames(