Feat: Delete useless request hooks. #10427 (#11659)

### What problem does this PR solve?

Feat: Delete useless request hooks. #10427

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-12-02 17:24:29 +08:00
committed by GitHub
parent 2ffe6f7439
commit ba6e2af5fd
101 changed files with 742 additions and 2590 deletions

View File

@ -3,7 +3,9 @@ import {
IFetchFileListResult,
IFolder,
} from '@/interfaces/database/file-manager';
import { IConnectRequestBody } from '@/interfaces/request/file-manager';
import fileManagerService from '@/services/file-manager-service';
import { downloadFileFromBlob } from '@/utils/file-util';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useDebounce } from 'ahooks';
import { PaginationProps } from 'antd';
@ -23,6 +25,10 @@ export const enum FileApiAction {
CreateFolder = 'createFolder',
FetchParentFolderList = 'fetchParentFolderList',
DeleteFile = 'deleteFile',
DownloadFile = 'downloadFile',
RenameFile = 'renameFile',
ConnectFileToKnowledge = 'connectFileToKnowledge',
FetchPureFileList = 'fetchPureFileList',
}
export const useGetFolderId = () => {
@ -229,3 +235,85 @@ export const useDeleteFile = () => {
return { data, loading, deleteFile: mutateAsync };
};
export const useDownloadFile = () => {
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [FileApiAction.DownloadFile],
mutationFn: async (params: { id: string; filename?: string }) => {
const response = await fileManagerService.getFile({}, params.id);
const blob = new Blob([response.data], { type: response.data.type });
downloadFileFromBlob(blob, params.filename);
},
});
return { data, loading, downloadFile: mutateAsync };
};
export const useRenameFile = () => {
const queryClient = useQueryClient();
const { t } = useTranslation();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [FileApiAction.RenameFile],
mutationFn: async (params: { fileId: string; name: string }) => {
const { data } = await fileManagerService.renameFile(params);
if (data.code === 0) {
message.success(t('message.renamed'));
queryClient.invalidateQueries({
queryKey: [FileApiAction.FetchFileList],
});
}
return data.code;
},
});
return { data, loading, renameFile: mutateAsync };
};
export const useConnectToKnowledge = () => {
const queryClient = useQueryClient();
const { t } = useTranslation();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [FileApiAction.ConnectFileToKnowledge],
mutationFn: async (params: IConnectRequestBody) => {
const { data } = await fileManagerService.connectFileToKnowledge(params);
if (data.code === 0) {
message.success(t('message.operated'));
queryClient.invalidateQueries({
queryKey: [FileApiAction.FetchFileList],
});
}
return data.code;
},
});
return { data, loading, connectFileToKnowledge: mutateAsync };
};
export const useFetchPureFileList = () => {
const { mutateAsync, isPending: loading } = useMutation({
mutationKey: [FileApiAction.FetchPureFileList],
gcTime: 0,
mutationFn: async (parentId: string) => {
const { data } = await fileManagerService.listFile({
parent_id: parentId,
});
return data;
},
});
return { loading, fetchList: mutateAsync };
};