删除api适配器调试日志
This commit is contained in:
parent
3b0bddcbf3
commit
603de3f0d5
@ -12,7 +12,6 @@ import datetime
|
||||
import requests
|
||||
import pytz
|
||||
from jingrow.config import Config
|
||||
from jingrow import log_error
|
||||
|
||||
class ApiAdapter:
|
||||
"""API 适配器 - 通过 API 调用 Jingrow SaaS 版"""
|
||||
@ -122,7 +121,6 @@ class ApiAdapter:
|
||||
return {'success': False, 'error': 'API响应格式错误'}
|
||||
else:
|
||||
error_text = response.text
|
||||
log_error(f"API请求失败: {response.status_code}, 响应: {error_text}")
|
||||
return {'success': False, 'error': f'API请求失败 (HTTP {response.status_code}): {error_text}'}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': f'调用upload_file API异常: {str(e)}'}
|
||||
@ -140,13 +138,10 @@ class ApiAdapter:
|
||||
if result.get('success'):
|
||||
return result.get('field_mapping', {})
|
||||
else:
|
||||
log_error(f"获取字段映射失败: {result.get('error', '未知错误')}")
|
||||
return {}
|
||||
else:
|
||||
log_error(f"获取字段映射失败: HTTP {response.status_code}")
|
||||
return {}
|
||||
except Exception as e:
|
||||
log_error(f"获取字段映射异常: {str(e)}")
|
||||
return {}
|
||||
|
||||
def get_field_value_from_jingrow(self, pagetype: str, name: str, fieldname: str) -> Optional[Any]:
|
||||
@ -162,13 +157,10 @@ class ApiAdapter:
|
||||
if result.get('success'):
|
||||
return result.get('value')
|
||||
else:
|
||||
log_error(f"获取字段值失败: {result.get('error', '未知错误')}")
|
||||
return None
|
||||
else:
|
||||
log_error(f"获取字段值失败: HTTP {response.status_code}")
|
||||
return None
|
||||
except Exception as e:
|
||||
log_error(f"获取字段值异常: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_ai_settings_from_jingrow(self) -> Optional[Dict[str, Any]]:
|
||||
@ -179,29 +171,22 @@ class ApiAdapter:
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if result.get('session_expired'):
|
||||
log_error("Session已过期,请重新登录")
|
||||
return None
|
||||
if 'message' in result:
|
||||
result = result['message']
|
||||
if result.get('success'):
|
||||
return result.get('config', {})
|
||||
else:
|
||||
log_error(f"获取AI Settings失败: {result.get('error', '未知错误')}")
|
||||
return None
|
||||
else:
|
||||
log_error(f"获取AI Settings失败: HTTP {response.status_code}")
|
||||
return None
|
||||
except Exception as e:
|
||||
log_error(f"获取AI Settings配置异常: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_agent_detail(self, name: str, session_cookie: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
||||
try:
|
||||
api_url = f"{self.api_url}/api/action/jingrow.ai.utils.jlocal.get_local_ai_agent_detail"
|
||||
headers = self._get_headers()
|
||||
if not headers:
|
||||
log_error("JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置")
|
||||
return None
|
||||
payload = {"name": name}
|
||||
response = requests.post(api_url, headers=headers, json=payload, timeout=15)
|
||||
if response.status_code == 200:
|
||||
@ -212,18 +197,14 @@ class ApiAdapter:
|
||||
return message.get('data')
|
||||
return data
|
||||
else:
|
||||
log_error(f"Failed to get agent detail: HTTP {response.status_code}: {response.text}")
|
||||
return None
|
||||
except Exception as e:
|
||||
log_error(f"获取智能体详情异常: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_pg(self, pagetype: str, name: str, session_cookie: Optional[str] = None) -> Dict[str, Any]:
|
||||
try:
|
||||
api_url = f"{self.api_url}/api/data/{pagetype}/{name}"
|
||||
headers = self._get_headers()
|
||||
if not headers:
|
||||
return {'success': False, 'error': 'JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置'}
|
||||
response = requests.get(api_url, headers=headers, timeout=15)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
@ -272,8 +253,6 @@ class ApiAdapter:
|
||||
try:
|
||||
api_url = f"{self.api_url}/api/action/jingrow.core.pagetype.local_job.local_job.push_local_job"
|
||||
headers = self._get_headers()
|
||||
if not headers:
|
||||
return {'success': False, 'error': 'JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置'}
|
||||
headers.setdefault("X-Requested-With", "XMLHttpRequest")
|
||||
site_name = getattr(Config, "JINGROW_SITE", None) or os.getenv("JINGROW_SITE")
|
||||
if site_name:
|
||||
@ -285,12 +264,9 @@ class ApiAdapter:
|
||||
body = body['message']
|
||||
if isinstance(body, dict) and body.get('success'):
|
||||
return {'success': True}
|
||||
log_error(f"[JFLOW->JINGROW] 推送失败(body): {body}")
|
||||
return {'success': False, 'error': str(body)}
|
||||
log_error(f"[JFLOW->JINGROW] 推送失败(HTTP): {resp.status_code} {resp.text}")
|
||||
return {'success': False, 'error': f"HTTP {resp.status_code}: {resp.text}"}
|
||||
except Exception as e:
|
||||
log_error(f"[JFLOW->JINGROW] 推送异常: {str(e)}")
|
||||
return {'success': False, 'error': f"推送 Local Job 失败: {str(e)}"}
|
||||
|
||||
def delete_pg(self, pagetype: str, name: str) -> Dict[str, Any]:
|
||||
@ -371,8 +347,6 @@ class ApiAdapter:
|
||||
try:
|
||||
api_url = f"{self.api_url}/api/action/jingrow.ai.utils.jlocal.get_pagetype_module_app"
|
||||
headers = self._get_headers()
|
||||
if not headers:
|
||||
return {'success': False, 'error': 'JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置'}
|
||||
payload = {"pagetype": pagetype}
|
||||
response = requests.post(api_url, json=payload, headers=headers, timeout=10)
|
||||
if response.status_code == 200:
|
||||
@ -416,8 +390,6 @@ class ApiAdapter:
|
||||
def get_jingrow_system_timezone(self):
|
||||
try:
|
||||
headers = self._get_headers()
|
||||
if not headers:
|
||||
return self._get_default_timezone()
|
||||
url = f"{self.api_url}/api/action/jingrow.core.pagetype.system_settings.system_settings.load"
|
||||
response = requests.post(url, headers=headers, timeout=5)
|
||||
if response.status_code == 200:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user