mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-14 17:08:31 +08:00
Fixed an issue where cited webpages could not be opened during online searches. (#16840)
This commit is contained in:
@@ -43,6 +43,7 @@ export function ReferenceDocumentList({ list }: { list: Docagg[] }) {
|
||||
documentId={selectedDocument.doc_id}
|
||||
chunk={{
|
||||
document_name: selectedDocument.doc_name,
|
||||
document_url: selectedDocument.url,
|
||||
}}
|
||||
></PdfDrawer>
|
||||
)}
|
||||
|
||||
@@ -167,6 +167,7 @@ export interface IChunk {
|
||||
doc_id: string;
|
||||
doc_name: string;
|
||||
doc_type_kwd?: ChunkDocType;
|
||||
document_url?: string;
|
||||
image_id: string;
|
||||
important_kwd?: string[];
|
||||
question_kwd?: string[]; // keywords
|
||||
|
||||
@@ -9,12 +9,17 @@ import { IModalProps } from '@/interfaces/common';
|
||||
import { IReferenceChunk } from '@/interfaces/database/chat';
|
||||
import { IChunk } from '@/interfaces/database/dataset';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
interface IProps extends IModalProps<any> {
|
||||
documentId: string;
|
||||
chunk: IChunk &
|
||||
IReferenceChunk & { docnm_kwd: string; document_name: string };
|
||||
chunk: {
|
||||
docnm_kwd?: string;
|
||||
document_name?: string;
|
||||
positions?: number[][];
|
||||
content_with_weight?: string;
|
||||
content?: string | null;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
function getFileExtensionRegex(filename: string): string {
|
||||
const match = filename.match(/\.([^.]+)$/);
|
||||
@@ -27,27 +32,32 @@ const PdfDrawer = ({
|
||||
chunk,
|
||||
}: IProps) => {
|
||||
const getDocumentUrl = useGetDocumentUrl(documentId);
|
||||
const { highlights, setWidthAndHeight } = useGetChunkHighlights(chunk);
|
||||
const { highlights, setWidthAndHeight } = useGetChunkHighlights(
|
||||
chunk as IChunk | IReferenceChunk,
|
||||
);
|
||||
// const ref = useRef<(highlight: IHighlight) => void>(() => {});
|
||||
// const [loaded, setLoaded] = useState(false);
|
||||
const url = getDocumentUrl();
|
||||
|
||||
const [fileType, setFileType] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (chunk.docnm_kwd || chunk.document_name) {
|
||||
const type = getFileExtensionRegex(
|
||||
chunk.docnm_kwd || chunk.document_name,
|
||||
);
|
||||
setFileType(type);
|
||||
}
|
||||
}, [chunk.docnm_kwd, chunk.document_name]);
|
||||
const documentName = chunk.docnm_kwd || chunk.document_name;
|
||||
const fileType = documentName ? getFileExtensionRegex(documentName) : '';
|
||||
const isWebPage = !fileType && !!chunk.document_url;
|
||||
const url = isWebPage ? (chunk.document_url as string) : getDocumentUrl();
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<div className="flex items-center gap-2">
|
||||
<FileIcon name={chunk.docnm_kwd || chunk.document_name}></FileIcon>
|
||||
{chunk.docnm_kwd || chunk.document_name}
|
||||
<FileIcon name={documentName as string}></FileIcon>
|
||||
{isWebPage ? (
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-text-sub-title-invert underline"
|
||||
>
|
||||
{documentName}
|
||||
</a>
|
||||
) : (
|
||||
documentName
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
onCancel={hideModal}
|
||||
|
||||
Reference in New Issue
Block a user