mirror of
https://github.com/langgenius/dify.git
synced 2026-04-18 04:16:28 +08:00
refactor: replace bare dict with UtmInfo TypedDict in operation_service (#35055)
This commit is contained in:
parent
671c5cdd84
commit
d412cddf39
@ -20,7 +20,7 @@ from models.account import AccountStatus
|
|||||||
from models.dataset import RateLimitLog
|
from models.dataset import RateLimitLog
|
||||||
from models.model import DifySetup
|
from models.model import DifySetup
|
||||||
from services.feature_service import FeatureService, LicenseStatus
|
from services.feature_service import FeatureService, LicenseStatus
|
||||||
from services.operation_service import OperationService
|
from services.operation_service import OperationService, UtmInfo
|
||||||
|
|
||||||
from .error import NotInitValidateError, NotSetupError, UnauthorizedAndForceLogout
|
from .error import NotInitValidateError, NotSetupError, UnauthorizedAndForceLogout
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ def cloud_utm_record[**P, R](view: Callable[P, R]) -> Callable[P, R]:
|
|||||||
utm_info = request.cookies.get("utm_info")
|
utm_info = request.cookies.get("utm_info")
|
||||||
|
|
||||||
if utm_info:
|
if utm_info:
|
||||||
utm_info_dict: dict = json.loads(utm_info)
|
utm_info_dict: UtmInfo = json.loads(utm_info)
|
||||||
OperationService.record_utm(current_tenant_id, utm_info_dict)
|
OperationService.record_utm(current_tenant_id, utm_info_dict)
|
||||||
|
|
||||||
return view(*args, **kwargs)
|
return view(*args, **kwargs)
|
||||||
|
|||||||
@ -1,8 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
|
class UtmInfo(TypedDict, total=False):
|
||||||
|
"""Expected shape of the utm_info dict passed to record_utm.
|
||||||
|
|
||||||
|
All fields are optional; missing keys default to an empty string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
utm_source: str
|
||||||
|
utm_medium: str
|
||||||
|
utm_campaign: str
|
||||||
|
utm_content: str
|
||||||
|
utm_term: str
|
||||||
|
|
||||||
|
|
||||||
class OperationService:
|
class OperationService:
|
||||||
base_url = os.environ.get("BILLING_API_URL", "BILLING_API_URL")
|
base_url = os.environ.get("BILLING_API_URL", "BILLING_API_URL")
|
||||||
secret_key = os.environ.get("BILLING_API_SECRET_KEY", "BILLING_API_SECRET_KEY")
|
secret_key = os.environ.get("BILLING_API_SECRET_KEY", "BILLING_API_SECRET_KEY")
|
||||||
@ -17,7 +31,7 @@ class OperationService:
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def record_utm(cls, tenant_id: str, utm_info: dict):
|
def record_utm(cls, tenant_id: str, utm_info: UtmInfo):
|
||||||
params = {
|
params = {
|
||||||
"tenant_id": tenant_id,
|
"tenant_id": tenant_id,
|
||||||
"utm_source": utm_info.get("utm_source", ""),
|
"utm_source": utm_info.get("utm_source", ""),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user