mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
Follow-up to SSR prefetch migration (2833965). Eliminates the Zustand
middleman that was syncing TanStack Query data into a separate store.
- Remove useGlobalPublicStore Zustand store entirely
- Create hooks/use-global-public.ts with useSystemFeatures,
useSystemFeaturesQuery, useIsSystemFeaturesPending, useSetupStatusQuery
- Migrate all 93 consumers to import from @/hooks/use-global-public
- Simplify global-public-context.tsx to a thin provider component
- Update 18 test files to mock the new hook interface
- Fix SetupStatusResponse.setup_at type from Date to string (JSON)
- Fix setup-status.spec.ts mock target to match consoleClient
BREAKING CHANGE: useGlobalPublicStore is removed. Use useSystemFeatures()
from @/hooks/use-global-public instead.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import type { Plugin, PluginManifestInMarket } from '../../types'
|
|
import type { SystemFeatures } from '@/types/feature'
|
|
import { useSystemFeatures } from '@/hooks/use-global-public'
|
|
import { InstallationScope } from '@/types/feature'
|
|
|
|
type PluginProps = (Plugin | PluginManifestInMarket) & { from: 'github' | 'marketplace' | 'package' }
|
|
|
|
export function pluginInstallLimit(plugin: PluginProps, systemFeatures: SystemFeatures) {
|
|
if (systemFeatures.plugin_installation_permission.restrict_to_marketplace_only) {
|
|
if (plugin.from === 'github' || plugin.from === 'package')
|
|
return { canInstall: false }
|
|
}
|
|
|
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.ALL) {
|
|
return {
|
|
canInstall: true,
|
|
}
|
|
}
|
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.NONE) {
|
|
return {
|
|
canInstall: false,
|
|
}
|
|
}
|
|
const verification = plugin.verification || {}
|
|
if (!plugin.verification || !plugin.verification.authorized_category)
|
|
verification.authorized_category = 'langgenius'
|
|
|
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.OFFICIAL_ONLY) {
|
|
return {
|
|
canInstall: verification.authorized_category === 'langgenius',
|
|
}
|
|
}
|
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.OFFICIAL_AND_PARTNER) {
|
|
return {
|
|
canInstall: verification.authorized_category === 'langgenius' || verification.authorized_category === 'partner',
|
|
}
|
|
}
|
|
return {
|
|
canInstall: true,
|
|
}
|
|
}
|
|
|
|
export default function usePluginInstallLimit(plugin: PluginProps) {
|
|
const systemFeatures = useSystemFeatures()
|
|
return pluginInstallLimit(plugin, systemFeatures)
|
|
}
|