mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 05:23:57 +00:00
Fix plugin runtime cannot upload files (#3271)
* app logo * fix: plugin runtime cannot upload file
This commit is contained in:
@@ -76,7 +76,10 @@ const ChatInput = ({
|
||||
hasFileUploading
|
||||
} = useFileUpload({
|
||||
fileSelectConfig,
|
||||
fileCtrl
|
||||
fileCtrl,
|
||||
outLinkAuthData,
|
||||
appId,
|
||||
chatId
|
||||
});
|
||||
const havInput = !!inputValue || fileList.length > 0;
|
||||
const canSendMessage = havInput && !hasFileUploading;
|
||||
|
@@ -14,24 +14,23 @@ import { ChatBoxInputFormType, UserInputFileItemType } from '../type';
|
||||
import { AppFileSelectConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { documentFileType } from '@fastgpt/global/common/file/constants';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { ChatBoxContext } from '../Provider';
|
||||
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
||||
|
||||
type UseFileUploadOptions = {
|
||||
fileSelectConfig: AppFileSelectConfigType;
|
||||
fileCtrl: UseFieldArrayReturn<ChatBoxInputFormType, 'files', 'id'>;
|
||||
|
||||
outLinkAuthData?: OutLinkChatAuthProps;
|
||||
appId: string;
|
||||
chatId: string;
|
||||
};
|
||||
|
||||
export const useFileUpload = (props: UseFileUploadOptions) => {
|
||||
const { fileSelectConfig, fileCtrl } = props;
|
||||
const { fileSelectConfig, fileCtrl, outLinkAuthData, appId, chatId } = props;
|
||||
const { toast } = useToast();
|
||||
const { t } = useTranslation();
|
||||
const { feConfigs } = useSystemStore();
|
||||
|
||||
const outLinkAuthData = useContextSelector(ChatBoxContext, (v) => v.outLinkAuthData);
|
||||
const appId = useContextSelector(ChatBoxContext, (v) => v.appId);
|
||||
const chatId = useContextSelector(ChatBoxContext, (v) => v.chatId);
|
||||
|
||||
const {
|
||||
update: updateFiles,
|
||||
remove: removeFiles,
|
||||
|
@@ -33,6 +33,7 @@ const RenderInput = () => {
|
||||
const isChatting = useContextSelector(PluginRunContext, (v) => v.isChatting);
|
||||
const fileSelectConfig = useContextSelector(PluginRunContext, (v) => v.fileSelectConfig);
|
||||
const instruction = useContextSelector(PluginRunContext, (v) => v.instruction);
|
||||
const appId = useContextSelector(PluginRunContext, (v) => v.appId);
|
||||
const chatId = useContextSelector(PluginRunContext, (v) => v.chatId);
|
||||
const outLinkAuthData = useContextSelector(PluginRunContext, (v) => v.outLinkAuthData);
|
||||
|
||||
@@ -61,14 +62,17 @@ const RenderInput = () => {
|
||||
hasFileUploading
|
||||
} = useFileUpload({
|
||||
fileSelectConfig,
|
||||
fileCtrl
|
||||
fileCtrl,
|
||||
outLinkAuthData,
|
||||
appId,
|
||||
chatId
|
||||
});
|
||||
const isDisabledInput = histories.length > 0;
|
||||
|
||||
useRequest2(uploadFiles, {
|
||||
manual: false,
|
||||
errorToast: t('common:upload_file_error'),
|
||||
refreshDeps: [fileList, outLinkAuthData, chatId]
|
||||
refreshDeps: [fileList, outLinkAuthData]
|
||||
});
|
||||
/* Global files(abandon) <=== */
|
||||
|
||||
|
@@ -19,6 +19,7 @@ import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput';
|
||||
import { isEqual } from 'lodash';
|
||||
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
|
||||
import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';
|
||||
import { PluginRunContext } from '../context';
|
||||
|
||||
const JsonEditor = dynamic(() => import('@fastgpt/web/components/common/Textarea/JsonEditor'));
|
||||
|
||||
@@ -37,6 +38,9 @@ const FileSelector = ({
|
||||
|
||||
const variablesForm = useContextSelector(ChatItemContext, (v) => v.variablesForm);
|
||||
const histories = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
|
||||
const appId = useContextSelector(PluginRunContext, (v) => v.appId);
|
||||
const chatId = useContextSelector(PluginRunContext, (v) => v.chatId);
|
||||
const outLinkAuthData = useContextSelector(PluginRunContext, (v) => v.outLinkAuthData);
|
||||
|
||||
const fileCtrl = useFieldArray({
|
||||
control: variablesForm.control,
|
||||
@@ -58,8 +62,10 @@ const FileSelector = ({
|
||||
canSelectImg: input.canSelectImg ?? false,
|
||||
maxFiles: input.maxFiles ?? 5
|
||||
},
|
||||
// @ts-ignore
|
||||
fileCtrl
|
||||
outLinkAuthData,
|
||||
appId,
|
||||
chatId,
|
||||
fileCtrl: fileCtrl as any
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
@@ -53,18 +53,18 @@ const CreateModal = ({
|
||||
[AppTypeEnum.simple]: {
|
||||
icon: 'core/app/simpleBot',
|
||||
title: t('app:type.Create simple bot'),
|
||||
avatar: '/imgs/app/avatar/simple.svg',
|
||||
avatar: 'core/app/type/simpleFill',
|
||||
emptyCreateText: t('app:create_empty_app')
|
||||
},
|
||||
[AppTypeEnum.workflow]: {
|
||||
icon: 'core/app/type/workflowFill',
|
||||
avatar: '/imgs/app/avatar/workflow.svg',
|
||||
avatar: 'core/app/type/workflowFill',
|
||||
title: t('app:type.Create workflow bot'),
|
||||
emptyCreateText: t('app:create_empty_workflow')
|
||||
},
|
||||
[AppTypeEnum.plugin]: {
|
||||
icon: 'core/app/type/pluginFill',
|
||||
avatar: '/imgs/app/avatar/plugin.svg',
|
||||
avatar: 'core/app/type/pluginFill',
|
||||
title: t('app:type.Create plugin bot'),
|
||||
emptyCreateText: t('app:create_empty_plugin')
|
||||
}
|
||||
|
Reference in New Issue
Block a user