mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
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.
This commit is contained in:
parent
3874e58dc2
commit
015f82878e
@ -27,6 +27,7 @@ from core.trigger.entities.entities import (
|
|||||||
Unsubscription,
|
Unsubscription,
|
||||||
)
|
)
|
||||||
from core.trigger.errors import TriggerProviderCredentialValidationError
|
from core.trigger.errors import TriggerProviderCredentialValidationError
|
||||||
|
from services.plugin.plugin_service import PluginService
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -69,13 +70,23 @@ class PluginTriggerProviderController:
|
|||||||
"""
|
"""
|
||||||
Convert to API entity
|
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(
|
return TriggerProviderApiEntity(
|
||||||
author=self.entity.identity.author,
|
author=self.entity.identity.author,
|
||||||
name=self.entity.identity.name,
|
name=self.entity.identity.name,
|
||||||
label=self.entity.identity.label,
|
label=self.entity.identity.label,
|
||||||
description=self.entity.identity.description,
|
description=self.entity.identity.description,
|
||||||
icon=self.entity.identity.icon,
|
icon=icon,
|
||||||
icon_dark=self.entity.identity.icon_dark,
|
icon_dark=icon_dark,
|
||||||
tags=self.entity.identity.tags,
|
tags=self.entity.identity.tags,
|
||||||
plugin_id=self.plugin_id,
|
plugin_id=self.plugin_id,
|
||||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from mimetypes import guess_type
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from yarl import URL
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
from core.helper import marketplace
|
from core.helper import marketplace
|
||||||
@ -176,6 +177,14 @@ class PluginService:
|
|||||||
manager = PluginInstaller()
|
manager = PluginInstaller()
|
||||||
return manager.fetch_plugin_installation_by_ids(tenant_id, ids)
|
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
|
@staticmethod
|
||||||
def get_asset(tenant_id: str, asset_file: str) -> tuple[bytes, str]:
|
def get_asset(tenant_id: str, asset_file: str) -> tuple[bytes, str]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -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.provider import WorkflowToolProviderController
|
||||||
from core.tools.workflow_as_tool.tool import WorkflowTool
|
from core.tools.workflow_as_tool.tool import WorkflowTool
|
||||||
from models.tools import ApiToolProvider, BuiltinToolProvider, MCPToolProvider, WorkflowToolProvider
|
from models.tools import ApiToolProvider, BuiltinToolProvider, MCPToolProvider, WorkflowToolProvider
|
||||||
|
from services.plugin.plugin_service import PluginService
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ToolTransformService:
|
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
|
@classmethod
|
||||||
def get_tool_provider_icon_url(cls, provider_type: str, provider_name: str, icon: str | dict) -> Union[str, dict]:
|
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):
|
elif isinstance(provider, ToolProviderApiEntity):
|
||||||
if provider.plugin_id:
|
if provider.plugin_id:
|
||||||
if isinstance(provider.icon, str):
|
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
|
tenant_id=tenant_id, filename=provider.icon
|
||||||
)
|
)
|
||||||
if isinstance(provider.icon_dark, str) and provider.icon_dark:
|
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
|
tenant_id=tenant_id, filename=provider.icon_dark
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user