Fix plugin runtime cannot upload files (#3271)

* app logo

* fix: plugin runtime cannot upload file
This commit is contained in:
Archer
2024-11-28 22:47:24 +08:00
committed by shilin66
parent 60553dc70b
commit 58c44fc6bf
5 changed files with 27 additions and 15 deletions

View File

@@ -76,7 +76,10 @@ const ChatInput = ({
hasFileUploading hasFileUploading
} = useFileUpload({ } = useFileUpload({
fileSelectConfig, fileSelectConfig,
fileCtrl fileCtrl,
outLinkAuthData,
appId,
chatId
}); });
const havInput = !!inputValue || fileList.length > 0; const havInput = !!inputValue || fileList.length > 0;
const canSendMessage = havInput && !hasFileUploading; const canSendMessage = havInput && !hasFileUploading;

View File

@@ -14,24 +14,23 @@ import { ChatBoxInputFormType, UserInputFileItemType } from '../type';
import { AppFileSelectConfigType } from '@fastgpt/global/core/app/type'; import { AppFileSelectConfigType } from '@fastgpt/global/core/app/type';
import { documentFileType } from '@fastgpt/global/common/file/constants'; import { documentFileType } from '@fastgpt/global/common/file/constants';
import { useSystemStore } from '@/web/common/system/useSystemStore'; import { useSystemStore } from '@/web/common/system/useSystemStore';
import { useContextSelector } from 'use-context-selector'; import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
import { ChatBoxContext } from '../Provider';
type UseFileUploadOptions = { type UseFileUploadOptions = {
fileSelectConfig: AppFileSelectConfigType; fileSelectConfig: AppFileSelectConfigType;
fileCtrl: UseFieldArrayReturn<ChatBoxInputFormType, 'files', 'id'>; fileCtrl: UseFieldArrayReturn<ChatBoxInputFormType, 'files', 'id'>;
outLinkAuthData?: OutLinkChatAuthProps;
appId: string;
chatId: string;
}; };
export const useFileUpload = (props: UseFileUploadOptions) => { export const useFileUpload = (props: UseFileUploadOptions) => {
const { fileSelectConfig, fileCtrl } = props; const { fileSelectConfig, fileCtrl, outLinkAuthData, appId, chatId } = props;
const { toast } = useToast(); const { toast } = useToast();
const { t } = useTranslation(); const { t } = useTranslation();
const { feConfigs } = useSystemStore(); 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 { const {
update: updateFiles, update: updateFiles,
remove: removeFiles, remove: removeFiles,

View File

@@ -33,6 +33,7 @@ const RenderInput = () => {
const isChatting = useContextSelector(PluginRunContext, (v) => v.isChatting); const isChatting = useContextSelector(PluginRunContext, (v) => v.isChatting);
const fileSelectConfig = useContextSelector(PluginRunContext, (v) => v.fileSelectConfig); const fileSelectConfig = useContextSelector(PluginRunContext, (v) => v.fileSelectConfig);
const instruction = useContextSelector(PluginRunContext, (v) => v.instruction); const instruction = useContextSelector(PluginRunContext, (v) => v.instruction);
const appId = useContextSelector(PluginRunContext, (v) => v.appId);
const chatId = useContextSelector(PluginRunContext, (v) => v.chatId); const chatId = useContextSelector(PluginRunContext, (v) => v.chatId);
const outLinkAuthData = useContextSelector(PluginRunContext, (v) => v.outLinkAuthData); const outLinkAuthData = useContextSelector(PluginRunContext, (v) => v.outLinkAuthData);
@@ -61,14 +62,17 @@ const RenderInput = () => {
hasFileUploading hasFileUploading
} = useFileUpload({ } = useFileUpload({
fileSelectConfig, fileSelectConfig,
fileCtrl fileCtrl,
outLinkAuthData,
appId,
chatId
}); });
const isDisabledInput = histories.length > 0; const isDisabledInput = histories.length > 0;
useRequest2(uploadFiles, { useRequest2(uploadFiles, {
manual: false, manual: false,
errorToast: t('common:upload_file_error'), errorToast: t('common:upload_file_error'),
refreshDeps: [fileList, outLinkAuthData, chatId] refreshDeps: [fileList, outLinkAuthData]
}); });
/* Global files(abandon) <=== */ /* Global files(abandon) <=== */

View File

@@ -19,6 +19,7 @@ import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext'; import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext'; import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';
import { PluginRunContext } from '../context';
const JsonEditor = dynamic(() => import('@fastgpt/web/components/common/Textarea/JsonEditor')); const JsonEditor = dynamic(() => import('@fastgpt/web/components/common/Textarea/JsonEditor'));
@@ -37,6 +38,9 @@ const FileSelector = ({
const variablesForm = useContextSelector(ChatItemContext, (v) => v.variablesForm); const variablesForm = useContextSelector(ChatItemContext, (v) => v.variablesForm);
const histories = useContextSelector(ChatRecordContext, (v) => v.chatRecords); 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({ const fileCtrl = useFieldArray({
control: variablesForm.control, control: variablesForm.control,
@@ -58,8 +62,10 @@ const FileSelector = ({
canSelectImg: input.canSelectImg ?? false, canSelectImg: input.canSelectImg ?? false,
maxFiles: input.maxFiles ?? 5 maxFiles: input.maxFiles ?? 5
}, },
// @ts-ignore outLinkAuthData,
fileCtrl appId,
chatId,
fileCtrl: fileCtrl as any
}); });
useEffect(() => { useEffect(() => {

View File

@@ -53,18 +53,18 @@ const CreateModal = ({
[AppTypeEnum.simple]: { [AppTypeEnum.simple]: {
icon: 'core/app/simpleBot', icon: 'core/app/simpleBot',
title: t('app:type.Create simple bot'), title: t('app:type.Create simple bot'),
avatar: '/imgs/app/avatar/simple.svg', avatar: 'core/app/type/simpleFill',
emptyCreateText: t('app:create_empty_app') emptyCreateText: t('app:create_empty_app')
}, },
[AppTypeEnum.workflow]: { [AppTypeEnum.workflow]: {
icon: 'core/app/type/workflowFill', icon: 'core/app/type/workflowFill',
avatar: '/imgs/app/avatar/workflow.svg', avatar: 'core/app/type/workflowFill',
title: t('app:type.Create workflow bot'), title: t('app:type.Create workflow bot'),
emptyCreateText: t('app:create_empty_workflow') emptyCreateText: t('app:create_empty_workflow')
}, },
[AppTypeEnum.plugin]: { [AppTypeEnum.plugin]: {
icon: 'core/app/type/pluginFill', icon: 'core/app/type/pluginFill',
avatar: '/imgs/app/avatar/plugin.svg', avatar: 'core/app/type/pluginFill',
title: t('app:type.Create plugin bot'), title: t('app:type.Create plugin bot'),
emptyCreateText: t('app:create_empty_plugin') emptyCreateText: t('app:create_empty_plugin')
} }