+5
![dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)
![autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)







Jingyi
GitHub
yyh
Joel
hjlarry
fatelei
Asuka Minato
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Xiyuan Chen
gigglewang
Yunlu Wen
chariri
Evan
yyh
9b74df21d0
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: yyh <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: hjlarry <[email protected]> Co-authored-by: fatelei <[email protected]> Co-authored-by: Asuka Minato <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <[email protected]> Co-authored-by: gigglewang <[email protected]> Co-authored-by: Yunlu Wen <[email protected]> Co-authored-by: chariri <[email protected]> Co-authored-by: Evan <[email protected]> Co-authored-by: yyh <[email protected]>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import type { GetSystemFeaturesResponse } from '@dify/contracts/api/console/system-features/types.gen'
|
|
import type { Plugin, PluginManifestInMarket } from '../../types'
|
|
import { useQuery } 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
|
|
isLoading: boolean
|
|
}
|
|
|
|
export function pluginInstallLimit(plugin: PluginProps, systemFeatures: GetSystemFeaturesResponse) {
|
|
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,
|
|
isPending,
|
|
} = useQuery(systemFeaturesQueryOptions())
|
|
if (!systemFeatures) {
|
|
return {
|
|
canInstall: false,
|
|
isLoading: isPending,
|
|
}
|
|
}
|
|
|
|
return {
|
|
...pluginInstallLimit(plugin, systemFeatures),
|
|
isLoading: false,
|
|
}
|
|
}
|