Feat: Upload files in the chat box #3221 (#9483)

### What problem does this PR solve?
Feat: Upload files in the chat box #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-08-15 10:04:37 +08:00
committed by GitHub
parent 618d6bc924
commit 562349eb02
11 changed files with 233 additions and 37 deletions

View File

@ -30,6 +30,7 @@ export const enum ChatApiAction {
DeleteMessage = 'deleteMessage',
FetchMindMap = 'fetchMindMap',
FetchRelatedQuestions = 'fetchRelatedQuestions',
UploadAndParse = 'upload_and_parse',
}
export const useGetChatSearchParams = () => {
@ -163,6 +164,10 @@ export const useSetDialog = () => {
queryKey: [ChatApiAction.FetchDialogList],
});
queryClient.invalidateQueries({
queryKey: [ChatApiAction.FetchDialog],
});
message.success(
t(`message.${params.dialog_id ? 'modified' : 'created'}`),
);
@ -376,6 +381,34 @@ export const useDeleteMessage = () => {
return { data, loading, deleteMessage: mutateAsync };
};
export function useUploadAndParseFile() {
const { conversationId } = useGetChatSearchParams();
const { t } = useTranslation();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [ChatApiAction.UploadAndParse],
mutationFn: async (file: File) => {
const formData = new FormData();
formData.append('file', file);
formData.append('conversation_id', conversationId);
const { data } = await chatService.uploadAndParse(formData);
if (data.code === 0) {
message.success(t(`message.uploaded`));
}
return data;
},
});
return { data, loading, uploadAndParseFile: mutateAsync };
}
//#endregion
//#region search page