mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
fix: unify trigger url generation
This commit is contained in:
parent
fe0457b257
commit
538b639bef
@ -274,6 +274,8 @@ class EndpointConfig(BaseSettings):
|
||||
description="Template url for endpoint plugin", default="http://localhost:5002/e/{hook_id}"
|
||||
)
|
||||
|
||||
TRIGGER_URL: str = Field(description="Template url for triggers", default="http://localhost:5001")
|
||||
|
||||
|
||||
class FileAccessConfig(BaseSettings):
|
||||
"""
|
||||
|
||||
@ -49,11 +49,6 @@ class WebhookTriggerApi(Resource):
|
||||
if not webhook_trigger:
|
||||
raise NotFound("Webhook trigger not found for this node")
|
||||
|
||||
# Add computed fields for marshal_with
|
||||
base_url = dify_config.SERVICE_API_URL
|
||||
webhook_trigger.webhook_url = f"{base_url}/triggers/webhook/{webhook_trigger.webhook_id}" # type: ignore
|
||||
webhook_trigger.webhook_debug_url = f"{base_url}/triggers/webhook-debug/{webhook_trigger.webhook_id}" # type: ignore
|
||||
|
||||
return webhook_trigger
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,24 @@
|
||||
from yarl import URL
|
||||
|
||||
from configs import dify_config
|
||||
|
||||
"""
|
||||
Basic URL for thirdparty trigger services
|
||||
"""
|
||||
base_url = URL(dify_config.TRIGGER_URL)
|
||||
|
||||
def parse_endpoint_id(endpoint_id: str) -> str:
|
||||
return f"{dify_config.CONSOLE_API_URL}/triggers/plugin/{endpoint_id}"
|
||||
|
||||
def generate_plugin_trigger_endpoint_url(endpoint_id: str) -> str:
|
||||
"""
|
||||
Generate url for plugin trigger endpoint url
|
||||
"""
|
||||
|
||||
return str(base_url / "triggers" / "plugin" / endpoint_id)
|
||||
|
||||
|
||||
def generate_webhook_trigger_endpoint(webhook_id: str, debug: bool = False) -> str:
|
||||
"""
|
||||
Generate url for webhook trigger endpoint url
|
||||
"""
|
||||
|
||||
return str(base_url / "triggers" / ("webhook-debug" if debug else "webhook") / webhook_id)
|
||||
|
||||
@ -2,6 +2,7 @@ import json
|
||||
import time
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime
|
||||
from functools import cached_property
|
||||
from typing import Any, Optional, cast
|
||||
|
||||
import sqlalchemy as sa
|
||||
@ -11,7 +12,7 @@ from sqlalchemy.orm import Mapped, mapped_column
|
||||
from core.plugin.entities.plugin_daemon import CredentialType
|
||||
from core.trigger.entities.api_entities import TriggerProviderSubscriptionApiEntity
|
||||
from core.trigger.entities.entities import Subscription
|
||||
from core.trigger.utils.endpoint import parse_endpoint_id
|
||||
from core.trigger.utils.endpoint import generate_plugin_trigger_endpoint_url, generate_webhook_trigger_endpoint
|
||||
from libs.datetime_utils import naive_utc_now
|
||||
from models.base import Base
|
||||
from models.engine import db
|
||||
@ -77,7 +78,7 @@ class TriggerSubscription(Base):
|
||||
def to_entity(self) -> Subscription:
|
||||
return Subscription(
|
||||
expires_at=self.expires_at,
|
||||
endpoint=parse_endpoint_id(self.endpoint_id),
|
||||
endpoint=generate_plugin_trigger_endpoint_url(self.endpoint_id),
|
||||
parameters=self.parameters,
|
||||
properties=self.properties,
|
||||
)
|
||||
@ -87,7 +88,7 @@ class TriggerSubscription(Base):
|
||||
id=self.id,
|
||||
name=self.name,
|
||||
provider=self.provider_id,
|
||||
endpoint=parse_endpoint_id(self.endpoint_id),
|
||||
endpoint=generate_plugin_trigger_endpoint_url(self.endpoint_id),
|
||||
parameters=self.parameters,
|
||||
properties=self.properties,
|
||||
credential_type=CredentialType(self.credential_type),
|
||||
@ -293,6 +294,20 @@ class WorkflowWebhookTrigger(Base):
|
||||
server_onupdate=func.current_timestamp(),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def webhook_url(self):
|
||||
"""
|
||||
Generated webhook url
|
||||
"""
|
||||
return generate_webhook_trigger_endpoint(self.webhook_id)
|
||||
|
||||
@cached_property
|
||||
def webhook_debug_url(self):
|
||||
"""
|
||||
Generated debug webhook url
|
||||
"""
|
||||
return generate_webhook_trigger_endpoint(self.webhook_id, True)
|
||||
|
||||
|
||||
class WorkflowPluginTrigger(Base):
|
||||
"""
|
||||
|
||||
@ -22,7 +22,7 @@ from core.trigger.entities.entities import (
|
||||
from core.trigger.provider import PluginTriggerProviderController
|
||||
from core.trigger.trigger_manager import TriggerManager
|
||||
from core.trigger.utils.encryption import masked_credentials
|
||||
from core.trigger.utils.endpoint import parse_endpoint_id
|
||||
from core.trigger.utils.endpoint import generate_plugin_trigger_endpoint_url
|
||||
from extensions.ext_redis import redis_client
|
||||
from models.provider_ids import TriggerProviderID
|
||||
from services.trigger.trigger_provider_service import TriggerProviderService
|
||||
@ -144,7 +144,7 @@ class TriggerSubscriptionBuilderService:
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
provider_id=provider_id,
|
||||
endpoint=parse_endpoint_id(subscription_builder.endpoint_id),
|
||||
endpoint=generate_plugin_trigger_endpoint_url(subscription_builder.endpoint_id),
|
||||
parameters=subscription_builder.parameters,
|
||||
credentials=subscription_builder.credentials,
|
||||
credential_type=credential_type,
|
||||
@ -344,7 +344,7 @@ class TriggerSubscriptionBuilderService:
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
provider_id=provider_id,
|
||||
endpoint=parse_endpoint_id(subscription_builder.endpoint_id),
|
||||
endpoint=generate_plugin_trigger_endpoint_url(subscription_builder.endpoint_id),
|
||||
parameters=subscription_builder.parameters,
|
||||
credentials=subscription_builder.credentials,
|
||||
credential_type=credential_type,
|
||||
@ -378,7 +378,7 @@ class TriggerSubscriptionBuilderService:
|
||||
id=entity.id,
|
||||
name=entity.name or "",
|
||||
provider=entity.provider_id,
|
||||
endpoint=parse_endpoint_id(entity.endpoint_id),
|
||||
endpoint=generate_plugin_trigger_endpoint_url(entity.endpoint_id),
|
||||
parameters=entity.parameters,
|
||||
properties=entity.properties,
|
||||
credential_type=credential_type,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user