From 6c77134e82fa5831fb9a18393ac19a930f51f712 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Thu, 28 Nov 2024 22:47:24 +0800 Subject: [PATCH] Fix plugin runtime cannot upload files (#3271) * app logo * fix: plugin runtime cannot upload file --- .../chat/ChatContainer/ChatBox/Input/ChatInput.tsx | 5 ++++- .../ChatContainer/ChatBox/hooks/useFileUpload.tsx | 13 ++++++------- .../PluginRunBox/components/RenderInput.tsx | 8 ++++++-- .../PluginRunBox/components/renderPluginInput.tsx | 10 ++++++++-- .../src/pages/app/list/components/CreateModal.tsx | 6 +++--- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx index 720279e5fb46..48a53780797d 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx @@ -76,7 +76,10 @@ const ChatInput = ({ hasFileUploading } = useFileUpload({ fileSelectConfig, - fileCtrl + fileCtrl, + outLinkAuthData, + appId, + chatId }); const havInput = !!inputValue || fileList.length > 0; const canSendMessage = havInput && !hasFileUploading; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/hooks/useFileUpload.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/hooks/useFileUpload.tsx index e837cd73d9eb..11cd9c193b44 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/hooks/useFileUpload.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/hooks/useFileUpload.tsx @@ -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; + + 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, diff --git a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx index cb10ef26a309..a0fc4a1a6b92 100644 --- a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx @@ -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) <=== */ diff --git a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx index 32ae531a8b37..d1733625ed13 100644 --- a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx @@ -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(() => { diff --git a/projects/app/src/pages/app/list/components/CreateModal.tsx b/projects/app/src/pages/app/list/components/CreateModal.tsx index ce81398a0da5..5be5767793c3 100644 --- a/projects/app/src/pages/app/list/components/CreateModal.tsx +++ b/projects/app/src/pages/app/list/components/CreateModal.tsx @@ -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') }