From b57e10bb0867b1fcf94af720498ebe4f3fa10e55 Mon Sep 17 00:00:00 2001 From: NFish Date: Mon, 21 Apr 2025 10:55:11 +0800 Subject: [PATCH] fix: update api request both in explore and web app --- .../base/chat/chat-with-history/context.tsx | 2 -- .../components/base/chat/chat-with-history/hooks.tsx | 4 ++-- .../components/base/chat/chat-with-history/index.tsx | 5 ----- .../base/chat/chat-with-history/sidebar/index.tsx | 4 ++-- .../base/chat/embedded-chatbot/context.tsx | 2 -- .../components/base/chat/embedded-chatbot/hooks.tsx | 4 ++-- .../components/base/chat/embedded-chatbot/index.tsx | 12 +++--------- web/app/components/explore/installed-app/index.tsx | 6 +++--- web/app/components/share/text-generation/index.tsx | 8 +++----- web/service/access-control.ts | 9 +++++---- web/service/share.ts | 9 +++++++++ 11 files changed, 29 insertions(+), 36 deletions(-) diff --git a/web/app/components/base/chat/chat-with-history/context.tsx b/web/app/components/base/chat/chat-with-history/context.tsx index 0558049423..4d797b3a3d 100644 --- a/web/app/components/base/chat/chat-with-history/context.tsx +++ b/web/app/components/base/chat/chat-with-history/context.tsx @@ -18,7 +18,6 @@ import type { import { AccessMode } from '@/models/access-control' export type ChatWithHistoryContextValue = { - isFromExplore: boolean appInfoError?: any appInfoLoading?: boolean appMeta?: AppMeta @@ -56,7 +55,6 @@ export type ChatWithHistoryContextValue = { } export const ChatWithHistoryContext = createContext({ - isFromExplore: false, accessMode: AccessMode.SPECIFIC_GROUPS_MEMBERS, userCanAccess: false, currentConversationId: '', diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index cc3ad7ece8..74241452ef 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -73,8 +73,8 @@ function getFormattedChatList(messages: any[]) { export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { const isInstalledApp = useMemo(() => !!installedAppInfo, [installedAppInfo]) const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR(installedAppInfo ? null : 'appInfo', fetchAppInfo) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode(installedAppInfo?.app.id || appInfo?.app_id) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp(installedAppInfo?.app.id || appInfo?.app_id) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId: installedAppInfo?.app.id || appInfo?.app_id, isInstalledApp }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId: installedAppInfo?.app.id || appInfo?.app_id, isInstalledApp }) useAppFavicon({ enable: !installedAppInfo, diff --git a/web/app/components/base/chat/chat-with-history/index.tsx b/web/app/components/base/chat/chat-with-history/index.tsx index b794cd5e5d..d9be5cf066 100644 --- a/web/app/components/base/chat/chat-with-history/index.tsx +++ b/web/app/components/base/chat/chat-with-history/index.tsx @@ -105,12 +105,10 @@ const ChatWithHistory: FC = ({ export type ChatWithHistoryWrapProps = { installedAppInfo?: InstalledApp className?: string - isFromExplore?: boolean } const ChatWithHistoryWrap: FC = ({ installedAppInfo, className, - isFromExplore, }) => { const media = useBreakpoints() const isMobile = media === MediaType.mobile @@ -153,7 +151,6 @@ const ChatWithHistoryWrap: FC = ({ return ( = ({ const ChatWithHistoryWrapWithCheckToken: FC = ({ installedAppInfo, className, - isFromExplore = false, }) => { const [initialized, setInitialized] = useState(false) const [appUnavailable, setAppUnavailable] = useState(false) @@ -233,7 +229,6 @@ const ChatWithHistoryWrapWithCheckToken: FC = ({ ) } diff --git a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx index 18d30fde9b..3709920595 100644 --- a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx +++ b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx @@ -17,7 +17,7 @@ import { AccessMode } from '@/models/access-control' const Sidebar = () => { const { t } = useTranslation() const { - isFromExplore, + isInstalledApp, accessMode, appData, pinnedConversationList, @@ -120,7 +120,7 @@ const Sidebar = () => { }
- + {appData?.site.copyright && (
© {(new Date()).getFullYear()} {appData?.site.copyright} diff --git a/web/app/components/base/chat/embedded-chatbot/context.tsx b/web/app/components/base/chat/embedded-chatbot/context.tsx index b24344260f..36963f4677 100644 --- a/web/app/components/base/chat/embedded-chatbot/context.tsx +++ b/web/app/components/base/chat/embedded-chatbot/context.tsx @@ -17,7 +17,6 @@ import type { import { AccessMode } from '@/models/access-control' export type EmbeddedChatbotContextValue = { - isFromExplore: boolean accessMode?: AccessMode userCanAccess?: boolean appInfoError?: any @@ -50,7 +49,6 @@ export type EmbeddedChatbotContextValue = { } export const EmbeddedChatbotContext = createContext({ - isFromExplore: false, userCanAccess: false, accessMode: AccessMode.SPECIFIC_GROUPS_MEMBERS, currentConversationId: '', diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 90070d0cc0..a6c3a02a58 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -66,8 +66,8 @@ function getFormattedChatList(messages: any[]) { export const useEmbeddedChatbot = () => { const isInstalledApp = false const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', fetchAppInfo) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode(appInfo?.app_id) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp(appInfo?.app_id) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId: appInfo?.app_id, isInstalledApp }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId: appInfo?.app_id, isInstalledApp }) const appData = useMemo(() => { return appInfo diff --git a/web/app/components/base/chat/embedded-chatbot/index.tsx b/web/app/components/base/chat/embedded-chatbot/index.tsx index 384ec1dfb6..201f38a7f1 100644 --- a/web/app/components/base/chat/embedded-chatbot/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/index.tsx @@ -26,7 +26,6 @@ import Tooltip from '@/app/components/base/tooltip' const Chatbot = () => { const { t } = useTranslation() const { - isFromExplore, userCanAccess, isMobile, appInfoError, @@ -110,11 +109,7 @@ const Chatbot = () => { ) } -type EmbeddedChatbotProps = { - isFromExplore?: boolean -} - -const EmbeddedChatbotWrapper = ({ isFromExplore }: EmbeddedChatbotProps) => { +const EmbeddedChatbotWrapper = () => { const media = useBreakpoints() const isMobile = media === MediaType.mobile const themeBuilder = useThemeContext() @@ -150,7 +145,6 @@ const EmbeddedChatbotWrapper = ({ isFromExplore }: EmbeddedChatbotProps) => { } = useEmbeddedChatbot() return { } -const EmbeddedChatbot = ({ isFromExplore = false }: EmbeddedChatbotProps) => { +const EmbeddedChatbot = () => { const [initialized, setInitialized] = useState(false) const [appUnavailable, setAppUnavailable] = useState(false) const [isUnknownReason, setIsUnknownReason] = useState(false) @@ -214,7 +208,7 @@ const EmbeddedChatbot = ({ isFromExplore = false }: EmbeddedChatbotProps) => { if (appUnavailable) return - return + return } export default EmbeddedChatbot diff --git a/web/app/components/explore/installed-app/index.tsx b/web/app/components/explore/installed-app/index.tsx index 221ca12daa..7c5edbfe59 100644 --- a/web/app/components/explore/installed-app/index.tsx +++ b/web/app/components/explore/installed-app/index.tsx @@ -28,13 +28,13 @@ const InstalledApp: FC = ({ return (
{installedApp.app.mode !== 'completion' && installedApp.app.mode !== 'workflow' && ( - + )} {installedApp.app.mode === 'completion' && ( - + )} {installedApp.app.mode === 'workflow' && ( - + )}
) diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsx index 0f0accd2f8..ec6ca299c3 100644 --- a/web/app/components/share/text-generation/index.tsx +++ b/web/app/components/share/text-generation/index.tsx @@ -64,14 +64,12 @@ export type IMainProps = { isInstalledApp?: boolean installedAppInfo?: InstalledApp isWorkflow?: boolean - isFromExplore?: boolean } const TextGeneration: FC = ({ isInstalledApp = false, installedAppInfo, isWorkflow = false, - isFromExplore = false, }) => { const { notify } = Toast @@ -112,8 +110,8 @@ const TextGeneration: FC = ({ const [moreLikeThisConfig, setMoreLikeThisConfig] = useState(null) const [textToSpeechConfig, setTextToSpeechConfig] = useState(null) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode(appId) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp(appId) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId, isInstalledApp }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId, isInstalledApp }) // save message const [savedMessages, setSavedMessages] = useState([]) @@ -581,7 +579,7 @@ const TextGeneration: FC = ({ />
{siteInfo.title}
- +
{!isPC && (