mirror of
https://github.com/langgenius/dify.git
synced 2026-04-23 04:06:13 +08:00
refactor(web): use orpc keys for installed app params and meta
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import type { ChatConfig } from '@/app/components/base/chat/types'
|
||||
import type { AccessMode } from '@/models/access-control'
|
||||
import type { Banner } from '@/models/app'
|
||||
import type { App, AppCategory, InstalledApp } from '@/models/explore'
|
||||
import type { AppMeta } from '@/models/share'
|
||||
import type { AppModeEnum } from '@/types/app'
|
||||
import { type } from '@orpc/contract'
|
||||
import { base } from '../base'
|
||||
@ -86,6 +88,30 @@ export const exploreInstalledAppAccessModeContract = base
|
||||
.input(type<{ query: { appId: string } }>())
|
||||
.output(type<AppAccessModeResponse>())
|
||||
|
||||
export const exploreInstalledAppParametersContract = base
|
||||
.route({
|
||||
path: '/installed-apps/{appId}/parameters',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<{
|
||||
params: {
|
||||
appId: string
|
||||
}
|
||||
}>())
|
||||
.output(type<ChatConfig>())
|
||||
|
||||
export const exploreInstalledAppMetaContract = base
|
||||
.route({
|
||||
path: '/installed-apps/{appId}/meta',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<{
|
||||
params: {
|
||||
appId: string
|
||||
}
|
||||
}>())
|
||||
.output(type<AppMeta>())
|
||||
|
||||
export const exploreBannersContract = base
|
||||
.route({
|
||||
path: '/explore/banners',
|
||||
|
||||
@ -5,6 +5,8 @@ import {
|
||||
exploreAppsContract,
|
||||
exploreBannersContract,
|
||||
exploreInstalledAppAccessModeContract,
|
||||
exploreInstalledAppMetaContract,
|
||||
exploreInstalledAppParametersContract,
|
||||
exploreInstalledAppPinContract,
|
||||
exploreInstalledAppsContract,
|
||||
exploreInstalledAppUninstallContract,
|
||||
@ -47,6 +49,8 @@ export const consoleRouterContract = {
|
||||
uninstallInstalledApp: exploreInstalledAppUninstallContract,
|
||||
updateInstalledApp: exploreInstalledAppPinContract,
|
||||
appAccessMode: exploreInstalledAppAccessModeContract,
|
||||
installedAppParameters: exploreInstalledAppParametersContract,
|
||||
installedAppMeta: exploreInstalledAppMetaContract,
|
||||
banners: exploreBannersContract,
|
||||
},
|
||||
trialApps: {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import type { ChatConfig } from '@/app/components/base/chat/types'
|
||||
import type { ExploreAppDetailResponse } from '@/contract/console/explore'
|
||||
import type { AppMeta } from '@/models/share'
|
||||
import { consoleClient } from './client'
|
||||
|
||||
export const fetchAppList = (language?: string) => {
|
||||
@ -49,6 +51,18 @@ export const getAppAccessModeByAppId = (appId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchInstalledAppParams = (appId: string) => {
|
||||
return consoleClient.explore.installedAppParameters({
|
||||
params: { appId },
|
||||
}) as Promise<ChatConfig>
|
||||
}
|
||||
|
||||
export const fetchInstalledAppMeta = (appId: string) => {
|
||||
return consoleClient.explore.installedAppMeta({
|
||||
params: { appId },
|
||||
}) as Promise<AppMeta>
|
||||
}
|
||||
|
||||
export const fetchBanners = (language?: string) => {
|
||||
if (!language)
|
||||
return consoleClient.explore.banners({})
|
||||
|
||||
@ -4,8 +4,7 @@ import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import { useLocale } from '@/context/i18n'
|
||||
import { AccessMode } from '@/models/access-control'
|
||||
import { consoleQuery } from './client'
|
||||
import { fetchAppList, fetchBanners, fetchInstalledAppList, getAppAccessModeByAppId, uninstallApp, updatePinStatus } from './explore'
|
||||
import { AppSourceType, fetchAppMeta, fetchAppParams } from './share'
|
||||
import { fetchAppList, fetchBanners, fetchInstalledAppList, fetchInstalledAppMeta, fetchInstalledAppParams, getAppAccessModeByAppId, uninstallApp, updatePinStatus } from './explore'
|
||||
|
||||
type ExploreAppListData = {
|
||||
categories: AppCategory[]
|
||||
@ -17,11 +16,12 @@ export const useExploreAppList = () => {
|
||||
const exploreAppsInput = locale
|
||||
? { query: { language: locale } }
|
||||
: {}
|
||||
const exploreAppsLanguage = exploreAppsInput?.query?.language
|
||||
|
||||
return useQuery<ExploreAppListData>({
|
||||
queryKey: [...consoleQuery.explore.apps.queryKey({ input: exploreAppsInput }), locale],
|
||||
queryKey: [...consoleQuery.explore.apps.queryKey({ input: exploreAppsInput }), exploreAppsLanguage],
|
||||
queryFn: async () => {
|
||||
const { categories, recommended_apps } = await fetchAppList(locale)
|
||||
const { categories, recommended_apps } = await fetchAppList(exploreAppsLanguage)
|
||||
return {
|
||||
categories,
|
||||
allList: [...recommended_apps].sort((a, b) => a.position - b.position),
|
||||
@ -68,12 +68,13 @@ export const useUpdateAppPinStatus = () => {
|
||||
export const useGetInstalledAppAccessModeByAppId = (appId: string | null) => {
|
||||
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
|
||||
const appAccessModeInput = { query: { appId: appId ?? '' } }
|
||||
const installedAppId = appAccessModeInput.query.appId
|
||||
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
...consoleQuery.explore.appAccessMode.queryKey({ input: appAccessModeInput }),
|
||||
systemFeatures.webapp_auth.enabled,
|
||||
appId,
|
||||
installedAppId,
|
||||
],
|
||||
queryFn: () => {
|
||||
if (systemFeatures.webapp_auth.enabled === false) {
|
||||
@ -81,36 +82,42 @@ export const useGetInstalledAppAccessModeByAppId = (appId: string | null) => {
|
||||
accessMode: AccessMode.PUBLIC,
|
||||
}
|
||||
}
|
||||
if (!appId)
|
||||
if (!installedAppId)
|
||||
return Promise.reject(new Error('App code is required to get access mode'))
|
||||
|
||||
return getAppAccessModeByAppId(appId)
|
||||
return getAppAccessModeByAppId(installedAppId)
|
||||
},
|
||||
enabled: !!appId,
|
||||
enabled: !!installedAppId,
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetInstalledAppParams = (appId: string | null) => {
|
||||
const installedAppParamsInput = { params: { appId: appId ?? '' } }
|
||||
const installedAppId = installedAppParamsInput.params.appId
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['explore', 'appParams', appId],
|
||||
queryKey: [...consoleQuery.explore.installedAppParameters.queryKey({ input: installedAppParamsInput }), installedAppId],
|
||||
queryFn: () => {
|
||||
if (!appId || appId.length === 0)
|
||||
if (!installedAppId)
|
||||
return Promise.reject(new Error('App ID is required to get app params'))
|
||||
return fetchAppParams(AppSourceType.installedApp, appId)
|
||||
return fetchInstalledAppParams(installedAppId)
|
||||
},
|
||||
enabled: !!appId,
|
||||
enabled: !!installedAppId,
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetInstalledAppMeta = (appId: string | null) => {
|
||||
const installedAppMetaInput = { params: { appId: appId ?? '' } }
|
||||
const installedAppId = installedAppMetaInput.params.appId
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['explore', 'appMeta', appId],
|
||||
queryKey: [...consoleQuery.explore.installedAppMeta.queryKey({ input: installedAppMetaInput }), installedAppId],
|
||||
queryFn: () => {
|
||||
if (!appId || appId.length === 0)
|
||||
if (!installedAppId)
|
||||
return Promise.reject(new Error('App ID is required to get app meta'))
|
||||
return fetchAppMeta(AppSourceType.installedApp, appId)
|
||||
return fetchInstalledAppMeta(installedAppId)
|
||||
},
|
||||
enabled: !!appId,
|
||||
enabled: !!installedAppId,
|
||||
})
|
||||
}
|
||||
|
||||
@ -118,11 +125,12 @@ export const useGetBanners = (locale?: string) => {
|
||||
const bannersInput = locale
|
||||
? { query: { language: locale } }
|
||||
: {}
|
||||
const bannersLanguage = bannersInput?.query?.language
|
||||
|
||||
return useQuery({
|
||||
queryKey: [...consoleQuery.explore.banners.queryKey({ input: bannersInput }), locale],
|
||||
queryKey: [...consoleQuery.explore.banners.queryKey({ input: bannersInput }), bannersLanguage],
|
||||
queryFn: () => {
|
||||
return fetchBanners(locale)
|
||||
return fetchBanners(bannersLanguage)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user