mirror of
https://github.com/langgenius/dify.git
synced 2026-07-26 22:28:32 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: GareArc <garethcxy@dify.ai>
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import type { GetSystemFeaturesResponse } from '@dify/contracts/api/console/system-features/types.gen'
|
|
import type { Plugin, PluginManifestInMarket } from '../../types'
|
|
import { useSuspenseQuery } from '@tanstack/react-query'
|
|
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
|
|
import { InstallationScope } from '@/features/system-features/constants'
|
|
|
|
type PluginProps = (Plugin | PluginManifestInMarket) & {
|
|
from: 'github' | 'marketplace' | 'package'
|
|
}
|
|
type PluginInstallLimitResult = {
|
|
canInstall: boolean
|
|
}
|
|
|
|
export function pluginInstallLimit(
|
|
plugin: PluginProps,
|
|
systemFeatures: Pick<GetSystemFeaturesResponse, 'plugin_installation_permission'>,
|
|
) {
|
|
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): PluginInstallLimitResult {
|
|
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
|
|
|
|
return pluginInstallLimit(plugin, systemFeatures)
|
|
}
|