fix: add marketplace switch

This commit is contained in:
Yeuoly 2024-10-16 14:47:48 +08:00
parent 43ffccc8fd
commit 31cca4a849
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
6 changed files with 40 additions and 0 deletions

View File

@ -335,4 +335,5 @@ PLUGIN_REMOTE_INSTALL_HOST=localhost
INNER_API_KEY=QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
# Marketplace configuration
MARKETPLACE_ENABLED=true
MARKETPLACE_API_URL=https://marketplace.dify.ai

View File

@ -143,6 +143,11 @@ class MarketplaceConfig(BaseSettings):
Configuration for marketplace
"""
MARKETPLACE_ENABLED: bool = Field(
description="Enable or disable marketplace",
default=True,
)
MARKETPLACE_API_URL: HttpUrl = Field(
description="Marketplace API URL",
default="https://marketplace.dify.ai",

View File

@ -248,6 +248,20 @@ class PluginFetchInstallTaskApi(Resource):
return jsonable_encoder({"task": PluginService.fetch_install_task(tenant_id, task_id)})
class PluginDeleteInstallTaskApi(Resource):
@setup_required
@login_required
@account_initialization_required
def post(self, task_id: str):
user = current_user
if not user.is_admin_or_owner:
raise Forbidden()
tenant_id = user.current_tenant_id
return {"success": PluginService.delete_install_task(tenant_id, task_id)}
class PluginUninstallApi(Resource):
@setup_required
@login_required
@ -277,4 +291,5 @@ api.add_resource(PluginInstallFromMarketplaceApi, "/workspaces/current/plugin/in
api.add_resource(PluginFetchManifestApi, "/workspaces/current/plugin/fetch-manifest")
api.add_resource(PluginFetchInstallTasksApi, "/workspaces/current/plugin/tasks")
api.add_resource(PluginFetchInstallTaskApi, "/workspaces/current/plugin/tasks/<task_id>")
api.add_resource(PluginDeleteInstallTaskApi, "/workspaces/current/plugin/tasks/<task_id>/delete")
api.add_resource(PluginUninstallApi, "/workspaces/current/plugin/uninstall")

View File

@ -93,6 +93,16 @@ class PluginInstallationManager(BasePluginManager):
PluginInstallTask,
)
def delete_plugin_installation_task(self, tenant_id: str, task_id: str) -> bool:
"""
Delete a plugin installation task.
"""
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/management/install/tasks/{task_id}/delete",
bool,
)
def fetch_plugin_manifest(self, tenant_id: str, plugin_unique_identifier: str) -> PluginDeclaration:
"""
Fetch a plugin manifest.

View File

@ -42,6 +42,7 @@ class SystemFeatureModel(BaseModel):
sso_enforced_for_web: bool = False
sso_enforced_for_web_protocol: str = ""
enable_web_sso_switch_component: bool = False
enable_marketplace: bool = True
class FeatureService:
@ -64,6 +65,9 @@ class FeatureService:
system_features.enable_web_sso_switch_component = True
cls._fulfill_params_from_enterprise(system_features)
if dify_config.MARKETPLACE_ENABLED:
system_features.enable_marketplace = True
return system_features
@classmethod

View File

@ -60,6 +60,11 @@ class PluginService:
manager = PluginInstallationManager()
return manager.fetch_plugin_installation_task(tenant_id, task_id)
@staticmethod
def delete_install_task(tenant_id: str, task_id: str) -> bool:
manager = PluginInstallationManager()
return manager.delete_plugin_installation_task(tenant_id, task_id)
@staticmethod
def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> str:
"""