mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Delete useless request hooks. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
162 lines
4.0 KiB
TypeScript
162 lines
4.0 KiB
TypeScript
import { DocumentParserType } from '@/constants/knowledge';
|
|
import { useHandleChunkMethodSelectChange } from '@/hooks/logic-hooks';
|
|
import { useSelectParserList } from '@/hooks/use-user-setting-request';
|
|
import { FormInstance } from 'antd';
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
|
const ParserListMap = new Map([
|
|
[
|
|
['pdf'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.Manual,
|
|
DocumentParserType.Paper,
|
|
DocumentParserType.Book,
|
|
DocumentParserType.Laws,
|
|
DocumentParserType.Presentation,
|
|
DocumentParserType.One,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[
|
|
['doc', 'docx'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.Book,
|
|
DocumentParserType.Laws,
|
|
DocumentParserType.One,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Manual,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[
|
|
['xlsx', 'xls'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Table,
|
|
DocumentParserType.One,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[['ppt', 'pptx'], [DocumentParserType.Presentation]],
|
|
[
|
|
['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif', 'tiff', 'webp', 'svg', 'ico'],
|
|
[DocumentParserType.Picture],
|
|
],
|
|
[
|
|
['txt'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.Book,
|
|
DocumentParserType.Laws,
|
|
DocumentParserType.One,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Table,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[
|
|
['csv'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.Book,
|
|
DocumentParserType.Laws,
|
|
DocumentParserType.One,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Table,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[
|
|
['md'],
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.KnowledgeGraph,
|
|
],
|
|
],
|
|
[['json'], [DocumentParserType.Naive, DocumentParserType.KnowledgeGraph]],
|
|
[['eml'], [DocumentParserType.Email]],
|
|
]);
|
|
|
|
const getParserList = (
|
|
values: string[],
|
|
parserList: Array<{
|
|
value: string;
|
|
label: string;
|
|
}>,
|
|
) => {
|
|
return parserList.filter((x) => values?.some((y) => y === x.value));
|
|
};
|
|
|
|
export const useFetchParserListOnMount = (
|
|
documentId: string,
|
|
parserId: DocumentParserType,
|
|
documentExtension: string,
|
|
form: FormInstance,
|
|
) => {
|
|
const [selectedTag, setSelectedTag] = useState<DocumentParserType>();
|
|
const parserList = useSelectParserList();
|
|
const handleChunkMethodSelectChange = useHandleChunkMethodSelectChange(form);
|
|
|
|
const nextParserList = useMemo(() => {
|
|
const key = [...ParserListMap.keys()].find((x) =>
|
|
x.some((y) => y === documentExtension),
|
|
);
|
|
if (key) {
|
|
const values = ParserListMap.get(key);
|
|
return getParserList(values ?? [], parserList);
|
|
}
|
|
|
|
return getParserList(
|
|
[
|
|
DocumentParserType.Naive,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.Book,
|
|
DocumentParserType.Laws,
|
|
DocumentParserType.One,
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Table,
|
|
],
|
|
parserList,
|
|
);
|
|
}, [parserList, documentExtension]);
|
|
|
|
useEffect(() => {
|
|
setSelectedTag(parserId);
|
|
}, [parserId, documentId]);
|
|
|
|
const handleChange = (tag: string) => {
|
|
handleChunkMethodSelectChange(tag);
|
|
setSelectedTag(tag as DocumentParserType);
|
|
};
|
|
|
|
return { parserList: nextParserList, handleChange, selectedTag };
|
|
};
|
|
|
|
const hideAutoKeywords = [
|
|
DocumentParserType.Qa,
|
|
DocumentParserType.Table,
|
|
DocumentParserType.Resume,
|
|
DocumentParserType.KnowledgeGraph,
|
|
DocumentParserType.Tag,
|
|
];
|
|
|
|
export const useShowAutoKeywords = () => {
|
|
const showAutoKeywords = useCallback(
|
|
(selectedTag: DocumentParserType | undefined) => {
|
|
return hideAutoKeywords.every((x) => selectedTag !== x);
|
|
},
|
|
[],
|
|
);
|
|
|
|
return showAutoKeywords;
|
|
};
|