fix:domain map
This commit is contained in:
parent
66c4e7ff05
commit
4bf7ee9988
@ -117,9 +117,18 @@ class APICaller:
|
||||
- An APICallDetail Pydantic model instance.
|
||||
"""
|
||||
merged_headers = {**self.default_headers, **(request_data.headers or {})}
|
||||
|
||||
# 🔧 移除User-Agent头(DMS API不需要)
|
||||
if 'User-Agent' in merged_headers:
|
||||
del merged_headers['User-Agent']
|
||||
|
||||
timeout = request_data.timeout or self.default_timeout
|
||||
json_payload = request_data.json_data
|
||||
|
||||
# 🔧 确保POST请求有空对象body(如果没有提供json_data)
|
||||
if request_data.method.upper() == 'POST' and json_payload is None and request_data.data is None:
|
||||
json_payload = {} # 空对象
|
||||
|
||||
# Generate cURL command before making the request
|
||||
curl_command = self._generate_curl_command(request_data, merged_headers)
|
||||
|
||||
@ -130,7 +139,11 @@ class APICaller:
|
||||
request_body_for_log = request_data.data # Store as is, might be dict or str
|
||||
|
||||
try:
|
||||
response = requests.request(
|
||||
# 🔧 创建session并禁用默认User-Agent
|
||||
session = requests.Session()
|
||||
session.headers.clear() # 清除所有默认头
|
||||
|
||||
response = session.request(
|
||||
method=request_data.method.upper(),
|
||||
url=str(request_data.url),
|
||||
headers=merged_headers,
|
||||
|
||||
@ -555,6 +555,16 @@ class InputParser:
|
||||
self.logger.warning(f"Could not load or parse domain map file '{domain_mapping_path}'. Using default domain. Error: {e}")
|
||||
DOMAIN_MAP = {}
|
||||
|
||||
# 🔧 构建关键词到领域ID的映射表
|
||||
keyword_to_domain_id = {}
|
||||
for domain_id, domain_info in DOMAIN_MAP.items():
|
||||
if isinstance(domain_info, dict) and 'keywords' in domain_info:
|
||||
keywords = domain_info['keywords']
|
||||
if isinstance(keywords, list):
|
||||
for keyword in keywords:
|
||||
keyword_to_domain_id[keyword] = domain_id
|
||||
self.logger.debug(f"映射关键词 '{keyword}' -> 领域ID '{domain_id}'")
|
||||
|
||||
list_url = urljoin(base_url, "/api/schema/manage/schema")
|
||||
self.logger.info(f"Fetching API list from: {list_url}")
|
||||
try:
|
||||
@ -591,7 +601,22 @@ class InputParser:
|
||||
self.logger.warning(f"Skipping an item in API list because it's missing 'domain', 'name', or 'id': {item}")
|
||||
continue
|
||||
|
||||
# 🔧 改进领域映射:支持精确匹配和前缀匹配
|
||||
instance_code = keyword_to_domain_id.get(domain_name)
|
||||
if instance_code:
|
||||
self.logger.info(f"通过精确关键词匹配:'{domain_name}' -> '{instance_code}'")
|
||||
else:
|
||||
# 尝试前缀匹配(如wb_cd匹配wb)
|
||||
for keyword, domain_id in keyword_to_domain_id.items():
|
||||
if domain_name.startswith(keyword + '_'): # wb_cd以wb_开头
|
||||
instance_code = domain_id
|
||||
self.logger.info(f"通过前缀关键词匹配:'{domain_name}' -> '{instance_code}' (匹配关键词: '{keyword}')")
|
||||
break
|
||||
|
||||
if not instance_code:
|
||||
# Fallback到原有的直接映射
|
||||
instance_code = DOMAIN_MAP.get(domain_name, domain_name)
|
||||
self.logger.info(f"使用直接映射:'{domain_name}' -> '{instance_code}'")
|
||||
model_url = urljoin(base_url, f"/api/schema/manage/schema/{model_id}")
|
||||
self.logger.info(f"Fetching model for '{name}' from: {model_url}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user