From 7afa8f00b8a73b7c5b2fd743f6d9a473e9253c6f Mon Sep 17 00:00:00 2001 From: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:05:23 +0800 Subject: [PATCH] pref: trim the input of outlink (#2860) --- .../Publish/FeiShu/FeiShuEditModal.tsx | 34 +++++++++++++------ .../OffiAccount/OffiAccountEditModal.tsx | 34 ++++++++++++++----- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/projects/app/src/pages/app/detail/components/Publish/FeiShu/FeiShuEditModal.tsx b/projects/app/src/pages/app/detail/components/Publish/FeiShu/FeiShuEditModal.tsx index 19ebc13aeb9..4bc10b272ff 100644 --- a/projects/app/src/pages/app/detail/components/Publish/FeiShu/FeiShuEditModal.tsx +++ b/projects/app/src/pages/app/detail/components/Publish/FeiShu/FeiShuEditModal.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Flex, Box, Button, ModalFooter, ModalBody, Input, Link, Grid } from '@chakra-ui/react'; +import { Flex, Box, Button, ModalBody, Input, Link } from '@chakra-ui/react'; import MyModal from '@fastgpt/web/components/common/MyModal'; import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant'; import type { FeishuAppType, OutLinkEditType } from '@fastgpt/global/support/outLink/type'; @@ -11,7 +11,6 @@ import BasicInfo from '../components/BasicInfo'; import { getDocPath } from '@/web/common/system/doc'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import MyIcon from '@fastgpt/web/components/common/Icon'; -import { useSystem } from '@fastgpt/web/hooks/useSystem'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; const FeiShuEditModal = ({ @@ -39,11 +38,16 @@ const FeiShuEditModal = ({ }); const { runAsync: onclickCreate, loading: creating } = useRequest2( - (e) => + (e: Omit, 'appId' | 'type'>) => createShareChat({ ...e, appId, - type: PublishChannelEnum.feishu + type: PublishChannelEnum.feishu, + app: { + appId: e?.app?.appId?.trim(), + appSecret: e.app?.appSecret?.trim(), + encryptKey: e.app?.encryptKey?.trim() + } }), { errorToast: t('common:common.Create Failed'), @@ -52,14 +56,24 @@ const FeiShuEditModal = ({ } ); - const { runAsync: onclickUpdate, loading: updating } = useRequest2((e) => updateShareChat(e), { - errorToast: t('common:common.Update Failed'), - successToast: t('common:common.Update Success'), - onSuccess: onEdit - }); + const { runAsync: onclickUpdate, loading: updating } = useRequest2( + (e) => + updateShareChat({ + ...e, + app: { + appId: e?.app?.appId?.trim(), + appSecret: e.app?.appSecret?.trim(), + encryptKey: e.app?.encryptKey?.trim() + } + }), + { + errorToast: t('common:common.Update Failed'), + successToast: t('common:common.Update Success'), + onSuccess: onEdit + } + ); const { feConfigs } = useSystemStore(); - const { isPc } = useSystem(); return ( - createShareChat({ + (e: OutLinkEditType) => { + if (e?.app) { + e.app.appId = e.app.appId?.trim(); + e.app.secret = e.app.secret?.trim(); + e.app.CallbackToken = e.app.CallbackToken?.trim(); + e.app.CallbackEncodingAesKey = e.app.CallbackEncodingAesKey?.trim(); + } + return createShareChat({ ...e, appId, type: PublishChannelEnum.officialAccount - }), + }); + }, { errorToast: t('common:common.Create Failed'), successToast: t('common:common.Create Success'), @@ -51,11 +58,22 @@ const OffiAccountEditModal = ({ } ); - const { runAsync: onclickUpdate, loading: updating } = useRequest2((e) => updateShareChat(e), { - errorToast: t('common:common.Update Failed'), - successToast: t('common:common.Update Success'), - onSuccess: onEdit - }); + const { runAsync: onclickUpdate, loading: updating } = useRequest2( + (e) => { + if (e?.app) { + e.app.appId = e.app.appId?.trim(); + e.app.secret = e.app.secret?.trim(); + e.app.CallbackToken = e.app.CallbackToken?.trim(); + e.app.CallbackEncodingAesKey = e.app.CallbackEncodingAesKey?.trim(); + } + return updateShareChat(e); + }, + { + errorToast: t('common:common.Update Failed'), + successToast: t('common:common.Update Success'), + onSuccess: onEdit + } + ); const { feConfigs } = useSystemStore();