mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-14 00:48:26 +08:00
Refactor: API connectors (#14228)
### What problem does this PR solve? Refactor /api/v1/connectors to be more RESTful. ### Type of change - [x] Refactoring
This commit is contained in:
@@ -144,7 +144,7 @@ const SourceDetailPage = () => {
|
||||
];
|
||||
}, [detail, runSchedule]);
|
||||
|
||||
const { addLoading, handleAddOk } = useAddDataSource();
|
||||
const { addLoading, handleAddOk } = useAddDataSource({isEdit:true});
|
||||
|
||||
const onSubmit = useCallback(() => {
|
||||
formRef?.current?.submit();
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useGetPaginationWithRouter } from '@/hooks/logic-hooks';
|
||||
import dataSourceService, {
|
||||
dataSourceRebuild,
|
||||
dataSourceResume,
|
||||
dataSourceResume, dataSourceUpdate,
|
||||
deleteDataSource,
|
||||
featchDataSourceDetail,
|
||||
getDataSourceLogs,
|
||||
@@ -68,7 +68,7 @@ export const useListDataSource = () => {
|
||||
return { list, categorizedList: updatedDataSourceTemplates, isFetching };
|
||||
};
|
||||
|
||||
export const useAddDataSource = () => {
|
||||
export const useAddDataSource = ({isEdit=false}:{isEdit?:boolean} ) => {
|
||||
const [addSource, setAddSource] = useState<IDataSorceInfo | undefined>(
|
||||
undefined,
|
||||
);
|
||||
@@ -90,7 +90,9 @@ export const useAddDataSource = () => {
|
||||
const handleAddOk = useCallback(
|
||||
async (data: any) => {
|
||||
setAddLoading(true);
|
||||
const { data: res } = await dataSourceService.dataSourceSet(data);
|
||||
const { data: res } = isEdit
|
||||
? await dataSourceUpdate(data.id, data)
|
||||
: await dataSourceService.dataSourceSet(data);
|
||||
console.log('🚀 ~ handleAddOk ~ code:', res.code);
|
||||
if (res.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['data-source'] });
|
||||
|
||||
@@ -79,7 +79,7 @@ const DataSource = () => {
|
||||
handleAddOk,
|
||||
hideAddingModal,
|
||||
showAddingModal,
|
||||
} = useAddDataSource();
|
||||
} = useAddDataSource({});
|
||||
|
||||
return (
|
||||
<ProfileSettingWrapperCard
|
||||
|
||||
@@ -19,13 +19,17 @@ const dataSourceService = registerServer<keyof typeof methods>(
|
||||
);
|
||||
|
||||
export const deleteDataSource = (id: string) =>
|
||||
request.post(api.dataSourceDel(id));
|
||||
request.delete(api.dataSourceDel(id));
|
||||
export const dataSourceResume = (id: string, data: { resume: boolean }) => {
|
||||
return request.put(api.dataSourceResume(id), { data });
|
||||
return request.post(api.dataSourceResume(id), { data });
|
||||
};
|
||||
|
||||
export const dataSourceRebuild = (id: string, data: { kb_id: string }) => {
|
||||
return request.put(api.dataSourceRebuild(id), { data });
|
||||
return request.post(api.dataSourceRebuild(id), { data });
|
||||
};
|
||||
|
||||
export const dataSourceUpdate = (id: string, data: { kb_id: string }) => {
|
||||
return request.patch(api.dataSourceUpdate(id), { data });
|
||||
};
|
||||
|
||||
export const getDataSourceLogs = (id: string, params?: any) =>
|
||||
|
||||
@@ -35,19 +35,20 @@ export default {
|
||||
deleteFactory: `${webAPI}/llm/delete_factory`,
|
||||
|
||||
// data source
|
||||
dataSourceSet: `${webAPI}/connector/set`,
|
||||
dataSourceList: `${webAPI}/connector/list`,
|
||||
dataSourceDel: (id: string) => `${webAPI}/connector/${id}/rm`,
|
||||
dataSourceResume: (id: string) => `${webAPI}/connector/${id}/resume`,
|
||||
dataSourceRebuild: (id: string) => `${webAPI}/connector/${id}/rebuild`,
|
||||
dataSourceLogs: (id: string) => `${webAPI}/connector/${id}/logs`,
|
||||
dataSourceDetail: (id: string) => `${webAPI}/connector/${id}`,
|
||||
dataSourceUpdate: (id:string) => `${restAPIv1}/connectors/${id}`,
|
||||
dataSourceSet: `${restAPIv1}/connectors`,
|
||||
dataSourceList: `${restAPIv1}/connectors`,
|
||||
dataSourceDel: (id: string) => `${restAPIv1}/connectors/${id}`,
|
||||
dataSourceResume: (id: string) => `${restAPIv1}/connectors/${id}/resume`,
|
||||
dataSourceRebuild: (id: string) => `${restAPIv1}/connectors/${id}/rebuild`,
|
||||
dataSourceLogs: (id: string) => `${restAPIv1}/connectors/${id}/logs`,
|
||||
dataSourceDetail: (id: string) => `${restAPIv1}/connectors/${id}`,
|
||||
googleWebAuthStart: (type: 'google-drive' | 'gmail') =>
|
||||
`${webAPI}/connector/google/oauth/web/start?type=${type}`,
|
||||
`${restAPIv1}/connectors/google/oauth/web/start?type=${type}`,
|
||||
googleWebAuthResult: (type: 'google-drive' | 'gmail') =>
|
||||
`${webAPI}/connector/google/oauth/web/result?type=${type}`,
|
||||
boxWebAuthStart: () => `${webAPI}/connector/box/oauth/web/start`,
|
||||
boxWebAuthResult: () => `${webAPI}/connector/box/oauth/web/result`,
|
||||
`${restAPIv1}/connectors/google/oauth/web/result?type=${type}`,
|
||||
boxWebAuthStart: () => `${restAPIv1}/connectors/box/oauth/web/start`,
|
||||
boxWebAuthResult: () => `${restAPIv1}/connectors/box/oauth/web/result`,
|
||||
|
||||
// plugin
|
||||
llmTools: `${webAPI}/plugin/llm_tools`,
|
||||
|
||||
Reference in New Issue
Block a user