Skip to content

Commit

Permalink
Fix plugin runtime cannot upload files (#3271)
Browse files Browse the repository at this point in the history
* app logo

* fix: plugin runtime cannot upload file
  • Loading branch information
c121914yu authored Nov 28, 2024
1 parent 93e302b commit 6c77134
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ const ChatInput = ({
hasFileUploading
} = useFileUpload({
fileSelectConfig,
fileCtrl
fileCtrl,
outLinkAuthData,
appId,
chatId
});
const havInput = !!inputValue || fileList.length > 0;
const canSendMessage = havInput && !hasFileUploading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) <=== */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -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,
Expand All @@ -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(() => {
Expand Down
6 changes: 3 additions & 3 deletions projects/app/src/pages/app/list/components/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down

0 comments on commit 6c77134

Please sign in to comment.