| @classmethod | @classmethod | ||||
| def generate_builtin_tool_icon_url(cls, provider_id: str) -> str: | def generate_builtin_tool_icon_url(cls, provider_id: str) -> str: | ||||
| return ( | |||||
| dify_config.CONSOLE_API_URL | |||||
| + "/console/api/workspaces/current/tool-provider/builtin/" | |||||
| + provider_id | |||||
| + "/icon" | |||||
| return str( | |||||
| URL(dify_config.CONSOLE_API_URL or "/") | |||||
| / "console" | |||||
| / "api" | |||||
| / "workspaces" | |||||
| / "current" | |||||
| / "tool-provider" | |||||
| / "builtin" | |||||
| / provider_id | |||||
| / "icon" | |||||
| ) | ) | ||||
| @classmethod | @classmethod | ||||
| def generate_plugin_tool_icon_url(cls, tenant_id: str, filename: str) -> str: | def generate_plugin_tool_icon_url(cls, tenant_id: str, filename: str) -> str: | ||||
| return str( | return str( | ||||
| URL(dify_config.CONSOLE_API_URL) | |||||
| URL(dify_config.CONSOLE_API_URL or "/") | |||||
| / "console" | / "console" | ||||
| / "api" | / "api" | ||||
| / "workspaces" | / "workspaces" |
| class ToolTransformService: | class ToolTransformService: | ||||
| @classmethod | @classmethod | ||||
| def get_plugin_icon_url(cls, tenant_id: str, filename: str) -> str: | def get_plugin_icon_url(cls, tenant_id: str, filename: str) -> str: | ||||
| url_prefix = URL(dify_config.CONSOLE_API_URL) / "console" / "api" / "workspaces" / "current" / "plugin" / "icon" | |||||
| 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}) | return str(url_prefix % {"tenant_id": tenant_id, "filename": filename}) | ||||
| @classmethod | @classmethod | ||||
| """ | """ | ||||
| get tool provider icon url | get tool provider icon url | ||||
| """ | """ | ||||
| url_prefix = URL(dify_config.CONSOLE_API_URL) / "console" / "api" / "workspaces" / "current" / "tool-provider" | |||||
| url_prefix = ( | |||||
| URL(dify_config.CONSOLE_API_URL or "/") / "console" / "api" / "workspaces" / "current" / "tool-provider" | |||||
| ) | |||||
| if provider_type == ToolProviderType.BUILT_IN.value: | if provider_type == ToolProviderType.BUILT_IN.value: | ||||
| return str(url_prefix / "builtin" / provider_name / "icon") | return str(url_prefix / "builtin" / provider_name / "icon") |
| assert str(URL("https://dify.ai/api") / "v1") == expected_3 | assert str(URL("https://dify.ai/api") / "v1") == expected_3 | ||||
| assert str(URL("https://dify.ai/api/") / "v1") == expected_3 | assert str(URL("https://dify.ai/api/") / "v1") == expected_3 | ||||
| expected_4 = "api" | |||||
| assert str(URL("") / "api") == expected_4 | |||||
| expected_5 = "/api" | |||||
| assert str(URL("/") / "api") == expected_5 | |||||
| with pytest.raises(ValueError) as e1: | with pytest.raises(ValueError) as e1: | ||||
| str(URL("https://dify.ai") / "/api") | str(URL("https://dify.ai") / "/api") | ||||
| assert str(e1.value) == "Appending path '/api' starting from slash is forbidden" | assert str(e1.value) == "Appending path '/api' starting from slash is forbidden" |
| listen ${NGINX_PORT}; | listen ${NGINX_PORT}; | ||||
| server_name ${NGINX_SERVER_NAME}; | server_name ${NGINX_SERVER_NAME}; | ||||
| # Rule 1: Handle application entry points (preserve /app/{id}) | |||||
| location ~ ^/app/[a-f0-9-]+$ { | |||||
| proxy_pass http://api:5001; | |||||
| include proxy.conf; | |||||
| } | |||||
| # Rule 2: Handle static resource requests (remove /app/{id} prefix) | |||||
| location ~ ^/app/[a-f0-9-]+/(console/api/.*)$ { | |||||
| rewrite ^/app/[a-f0-9-]+/(.*)$ /$1 break; | |||||
| proxy_pass http://api:5001; | |||||
| include proxy.conf; | |||||
| } | |||||
| location /console/api { | location /console/api { | ||||
| proxy_pass http://api:5001; | proxy_pass http://api:5001; | ||||
| include proxy.conf; | include proxy.conf; |