feat: utm supports. (#2181)

This commit is contained in:
Garfield Dai 2024-01-24 20:14:02 +08:00 committed by GitHub
parent 3c13c4f3ee
commit 95ad06c8c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 1 deletions

View File

@ -11,10 +11,13 @@ from .app import (advanced_prompt_template, annotation, app, audio, completion,
model_config, site, statistic) model_config, site, statistic)
# Import auth controllers # Import auth controllers
from .auth import activate, data_source_oauth, login, oauth from .auth import activate, data_source_oauth, login, oauth
from .billing import billing
# Import datasets controllers # Import datasets controllers
from .datasets import data_source, datasets, datasets_document, datasets_segments, file, hit_testing from .datasets import data_source, datasets, datasets_document, datasets_segments, file, hit_testing
# Import explore controllers # Import explore controllers
from .explore import audio, completion, conversation, installed_app, message, parameter, recommended_app, saved_message from .explore import audio, completion, conversation, installed_app, message, parameter, recommended_app, saved_message
# Import workspace controllers # Import workspace controllers
from .workspace import account, members, model_providers, models, tool_providers, workspace from .workspace import account, members, model_providers, models, tool_providers, workspace
# Import billing controllers
from .billing import billing
# Import operation controllers
from .operation import operation

View File

@ -0,0 +1,30 @@
from flask_login import current_user
from flask_restful import Resource, reqparse
from controllers.console import api
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required, only_edition_cloud
from libs.login import login_required
from services.operation_service import OperationService
class TenantUtm(Resource):
@setup_required
@login_required
@account_initialization_required
@only_edition_cloud
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('utm_source', type=str, required=True)
parser.add_argument('utm_medium', type=str, required=True)
parser.add_argument('utm_campaign', type=str, required=False, default='')
parser.add_argument('utm_content', type=str, required=False, default='')
parser.add_argument('utm_term', type=str, required=False, default='')
args = parser.parse_args()
return OperationService.record_utm(current_user.current_tenant_id, args)
api.add_resource(TenantUtm, '/operation/utm')

View File

@ -0,0 +1,32 @@
import os
import requests
class OperationService:
base_url = os.environ.get('BILLING_API_URL', 'BILLING_API_URL')
secret_key = os.environ.get('BILLING_API_SECRET_KEY', 'BILLING_API_SECRET_KEY')
@classmethod
def _send_request(cls, method, endpoint, json=None, params=None):
headers = {
"Content-Type": "application/json",
"Billing-Api-Secret-Key": cls.secret_key
}
url = f"{cls.base_url}{endpoint}"
response = requests.request(method, url, json=json, params=params, headers=headers)
return response.json()
@classmethod
def record_utm(cls, tenant_id, args):
params = {
'tenant_id': tenant_id,
'utm_source': args['utm_source'],
'utm_medium': args['utm_medium'],
'utm_campaign': args['utm_campaign'],
'utm_content': args['utm_content'],
'utm_term': args['utm_term']
}
return cls._send_request('POST', '/tenant_utms', params=params)