From 015f82878e6e5bda800d3d49e95bfd9dbd3866ec Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 5 Sep 2025 12:01:41 +0800 Subject: [PATCH] feat(trigger): integrate plugin icon retrieval into trigger provider - Added `get_plugin_icon_url` method in `PluginService` to fetch plugin icons. - Updated `PluginTriggerProviderController` to use the new method for icon handling. - Refactored `ToolTransformService` to utilize `PluginService` for consistent icon URL generation. This enhances the trigger provider's ability to manage plugin icons effectively. --- api/core/trigger/provider.py | 15 +++++++++++++-- api/services/plugin/plugin_service.py | 9 +++++++++ api/services/tools/tools_transform_service.py | 13 ++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/api/core/trigger/provider.py b/api/core/trigger/provider.py index 9d95d6f1d4..dfbe456565 100644 --- a/api/core/trigger/provider.py +++ b/api/core/trigger/provider.py @@ -27,6 +27,7 @@ from core.trigger.entities.entities import ( Unsubscription, ) from core.trigger.errors import TriggerProviderCredentialValidationError +from services.plugin.plugin_service import PluginService logger = logging.getLogger(__name__) @@ -69,13 +70,23 @@ class PluginTriggerProviderController: """ Convert to API entity """ + icon = ( + PluginService.get_plugin_icon_url(self.tenant_id, self.entity.identity.icon) + if self.entity.identity.icon + else None + ) + icon_dark = ( + PluginService.get_plugin_icon_url(self.tenant_id, self.entity.identity.icon_dark) + if self.entity.identity.icon_dark + else None + ) return TriggerProviderApiEntity( author=self.entity.identity.author, name=self.entity.identity.name, label=self.entity.identity.label, description=self.entity.identity.description, - icon=self.entity.identity.icon, - icon_dark=self.entity.identity.icon_dark, + icon=icon, + icon_dark=icon_dark, tags=self.entity.identity.tags, plugin_id=self.plugin_id, plugin_unique_identifier=self.plugin_unique_identifier, diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 9005f0669b..0a50f78f79 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -4,6 +4,7 @@ from mimetypes import guess_type from typing import Optional from pydantic import BaseModel +from yarl import URL from configs import dify_config from core.helper import marketplace @@ -176,6 +177,14 @@ class PluginService: manager = PluginInstaller() return manager.fetch_plugin_installation_by_ids(tenant_id, ids) + @classmethod + def get_plugin_icon_url(cls, tenant_id: str, filename: str) -> str: + url_prefix = ( + URL(dify_config.CONSOLE_API_URL or "/") / "console" / "api" / "workspaces" / "current" / "plugin" / "icon" + ) + return str(url_prefix % {"tenant_id": tenant_id, "filename": filename}) + + @staticmethod def get_asset(tenant_id: str, asset_file: str) -> tuple[bytes, str]: """ diff --git a/api/services/tools/tools_transform_service.py b/api/services/tools/tools_transform_service.py index 5a05907f37..50269d7617 100644 --- a/api/services/tools/tools_transform_service.py +++ b/api/services/tools/tools_transform_service.py @@ -25,18 +25,13 @@ from core.tools.utils.encryption import create_provider_encrypter, create_tool_p from core.tools.workflow_as_tool.provider import WorkflowToolProviderController from core.tools.workflow_as_tool.tool import WorkflowTool from models.tools import ApiToolProvider, BuiltinToolProvider, MCPToolProvider, WorkflowToolProvider +from services.plugin.plugin_service import PluginService logger = logging.getLogger(__name__) class ToolTransformService: - @classmethod - def get_plugin_icon_url(cls, tenant_id: str, filename: str) -> str: - url_prefix = ( - URL(dify_config.CONSOLE_API_URL or "/") / "console" / "api" / "workspaces" / "current" / "plugin" / "icon" - ) - return str(url_prefix % {"tenant_id": tenant_id, "filename": filename}) - + @classmethod def get_tool_provider_icon_url(cls, provider_type: str, provider_name: str, icon: str | dict) -> Union[str, dict]: """ @@ -74,11 +69,11 @@ class ToolTransformService: elif isinstance(provider, ToolProviderApiEntity): if provider.plugin_id: if isinstance(provider.icon, str): - provider.icon = ToolTransformService.get_plugin_icon_url( + provider.icon = PluginService.get_plugin_icon_url( tenant_id=tenant_id, filename=provider.icon ) if isinstance(provider.icon_dark, str) and provider.icon_dark: - provider.icon_dark = ToolTransformService.get_plugin_icon_url( + provider.icon_dark = PluginService.get_plugin_icon_url( tenant_id=tenant_id, filename=provider.icon_dark ) else: