|
33 | 33 | from common.exception.app_exception import AppApiException |
34 | 34 | from common.field.common import UploadedImageField |
35 | 35 | from common.result import result |
36 | | -from common.utils.common import get_file_content, generate_uuid |
| 36 | +from common.utils.common import get_file_content, generate_uuid, bytes_to_uploaded_file |
37 | 37 | from common.utils.logger import maxkb_logger |
38 | 38 | from common.utils.rsa_util import rsa_long_decrypt, rsa_long_encrypt |
39 | 39 | from common.utils.tool_code import ToolExecutor |
@@ -400,6 +400,25 @@ def insert(self, instance, with_valid=True): |
400 | 400 | if instance.get('tool_type') == ToolType.MCP: |
401 | 401 | ToolExecutor().validate_mcp_transport(instance.get('code', '')) |
402 | 402 |
|
| 403 | + # 处理 work_flow_template |
| 404 | + if instance.get('work_flow_template') is not None: |
| 405 | + template_instance = instance.get('work_flow_template') |
| 406 | + download_url = template_instance.get('downloadUrl') |
| 407 | + # 查找匹配的版本名称 |
| 408 | + res = requests.get(download_url, timeout=5) |
| 409 | + tool = ToolSerializer.Import(data={ |
| 410 | + 'file': bytes_to_uploaded_file(res.content, 'file.tool'), |
| 411 | + 'user_id': self.data.get('user_id'), |
| 412 | + 'workspace_id': self.data.get('workspace_id'), |
| 413 | + 'folder_id': str(instance.get('folder_id', self.data.get('workspace_id'))), |
| 414 | + }).import_() |
| 415 | + |
| 416 | + try: |
| 417 | + requests.get(template_instance.get('downloadCallbackUrl'), timeout=5) |
| 418 | + except Exception as e: |
| 419 | + maxkb_logger.error(f"callback appstore tool download error: {e}") |
| 420 | + return tool |
| 421 | + |
403 | 422 | tool_id = uuid.uuid7() |
404 | 423 | Tool( |
405 | 424 | id=tool_id, |
@@ -860,7 +879,9 @@ def import_(self, scope=ToolScope.WORKSPACE): |
860 | 879 | 'auth_target_type': AuthTargetType.TOOL.value |
861 | 880 | }).auth_resource(str(tool_id)) |
862 | 881 |
|
863 | | - return True |
| 882 | + return ToolSerializer.Operate(data={ |
| 883 | + 'id': tool_id, 'workspace_id': self.data.get('workspace_id') |
| 884 | + }).one() |
864 | 885 |
|
865 | 886 | class IconOperate(serializers.Serializer): |
866 | 887 | id = serializers.UUIDField(required=True, label=_("function ID")) |
|
0 commit comments