mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-19 12:06:42 +08:00
feat: select the corresponding parsing method according to the file type and after the document is successfully uploaded, use the ChunkMethodModal to select the parsing method. and remove ChunkMethodModal from knowledge-file (#158)
* feat: select the corresponding parsing method according to the file type * feat: after the document is successfully uploaded, use the ChunkMethodModal to select the parsing method. * feat: add pdf types to ParserListMap * feat: remove ChunkMethodModal from knowledge-file
This commit is contained in:
@ -2,6 +2,7 @@ import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
|
||||
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
||||
import { api_host } from '@/utils/api';
|
||||
import { buildChunkHighlights } from '@/utils/documentUtils';
|
||||
import { UploadFile } from 'antd';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { IHighlight } from 'react-pdf-highlighter';
|
||||
import { useDispatch, useSelector } from 'umi';
|
||||
@ -174,3 +175,47 @@ export const useRemoveDocument = (documentId: string) => {
|
||||
|
||||
return removeDocument;
|
||||
};
|
||||
|
||||
export const useUploadDocument = () => {
|
||||
const dispatch = useDispatch();
|
||||
const { knowledgeId } = useGetKnowledgeSearchParams();
|
||||
|
||||
const uploadDocument = useCallback(
|
||||
(file: UploadFile) => {
|
||||
try {
|
||||
return dispatch<any>({
|
||||
type: 'kFModel/upload_document',
|
||||
payload: {
|
||||
file,
|
||||
kb_id: knowledgeId,
|
||||
},
|
||||
});
|
||||
} catch (errorInfo) {
|
||||
console.log('Failed:', errorInfo);
|
||||
}
|
||||
},
|
||||
[dispatch, knowledgeId],
|
||||
);
|
||||
|
||||
return uploadDocument;
|
||||
};
|
||||
|
||||
export const useRunDocument = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const runDocumentByIds = useCallback(
|
||||
(ids: string[]) => {
|
||||
try {
|
||||
return dispatch<any>({
|
||||
type: 'kFModel/document_run',
|
||||
payload: { doc_ids: ids, run: 1 },
|
||||
});
|
||||
} catch (errorInfo) {
|
||||
console.log('Failed:', errorInfo);
|
||||
}
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
|
||||
return runDocumentByIds;
|
||||
};
|
||||
|
||||
47
web/src/hooks/logicHooks.ts
Normal file
47
web/src/hooks/logicHooks.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
||||
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useSetModalState } from './commonHooks';
|
||||
import { useSetDocumentParser } from './documentHooks';
|
||||
import { useOneNamespaceEffectsLoading } from './storeHooks';
|
||||
|
||||
export const useChangeDocumentParser = (documentId: string) => {
|
||||
const setDocumentParser = useSetDocumentParser();
|
||||
|
||||
const {
|
||||
visible: changeParserVisible,
|
||||
hideModal: hideChangeParserModal,
|
||||
showModal: showChangeParserModal,
|
||||
} = useSetModalState();
|
||||
const loading = useOneNamespaceEffectsLoading('kFModel', [
|
||||
'document_change_parser',
|
||||
]);
|
||||
|
||||
const onChangeParserOk = useCallback(
|
||||
async (parserId: string, parserConfig: IChangeParserConfigRequestBody) => {
|
||||
const ret = await setDocumentParser(parserId, documentId, parserConfig);
|
||||
if (ret === 0) {
|
||||
hideChangeParserModal();
|
||||
}
|
||||
},
|
||||
[hideChangeParserModal, setDocumentParser, documentId],
|
||||
);
|
||||
|
||||
return {
|
||||
changeParserLoading: loading,
|
||||
onChangeParserOk,
|
||||
changeParserVisible,
|
||||
hideChangeParserModal,
|
||||
showChangeParserModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useSetSelectedRecord = <T = IKnowledgeFile>() => {
|
||||
const [currentRecord, setCurrentRecord] = useState<T>({} as T);
|
||||
|
||||
const setRecord = (record: T) => {
|
||||
setCurrentRecord(record);
|
||||
};
|
||||
|
||||
return { currentRecord, setRecord };
|
||||
};
|
||||
Reference in New Issue
Block a user