优化create_app函数
This commit is contained in:
parent
5566549ce3
commit
55afdb2c00
@ -300,53 +300,39 @@ async def create_app(
|
||||
try:
|
||||
url = f"{get_jingrow_cloud_url()}/api/action/jcloud.api.local_app.create_local_app"
|
||||
|
||||
app_data = {
|
||||
"app_name": app_name,
|
||||
"title": title,
|
||||
"subtitle": subtitle,
|
||||
"description": description,
|
||||
"category": category,
|
||||
"repository_url": repository_url,
|
||||
"file_url": file_url,
|
||||
"app_image": app_image
|
||||
}
|
||||
|
||||
headers = get_jingrow_cloud_api_headers()
|
||||
headers['Content-Type'] = 'application/json'
|
||||
|
||||
api_payload = {
|
||||
"app_data": app_data
|
||||
}
|
||||
response = requests.post(url, json={
|
||||
"app_data": {
|
||||
"app_name": app_name,
|
||||
"title": title,
|
||||
"subtitle": subtitle,
|
||||
"description": description,
|
||||
"category": category,
|
||||
"repository_url": repository_url,
|
||||
"file_url": file_url,
|
||||
"app_image": app_image
|
||||
}
|
||||
}, headers=headers, timeout=20)
|
||||
|
||||
response = requests.post(url, json=api_payload, headers=headers, timeout=20)
|
||||
if response.status_code != 200:
|
||||
error_detail = response.json().get('detail', f"HTTP {response.status_code}") if response.headers.get('content-type', '').startswith('application/json') else f"HTTP {response.status_code}"
|
||||
raise HTTPException(status_code=response.status_code, detail=error_detail)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
# 检查返回结果是否包含错误
|
||||
if isinstance(result, dict) and 'error' in result:
|
||||
raise HTTPException(status_code=400, detail=result['error'])
|
||||
|
||||
# 检查message字段中的结果
|
||||
message = result.get('message', {})
|
||||
if isinstance(message, dict) and 'error' in message:
|
||||
raise HTTPException(status_code=400, detail=message['error'])
|
||||
|
||||
# 成功情况
|
||||
if isinstance(message, dict) and message.get('success'):
|
||||
app_name = message.get('name', 'unknown')
|
||||
return {"success": True, "message": f"应用发布成功,应用名称: {app_name}"}
|
||||
|
||||
# 兼容旧格式
|
||||
app_name = result.get('message', 'unknown')
|
||||
return {"success": True, "message": f"应用发布成功,应用名称: {app_name}"}
|
||||
result = response.json()
|
||||
|
||||
# 处理HTTP错误状态码
|
||||
try:
|
||||
error_detail = response.json().get('detail', f"HTTP {response.status_code}")
|
||||
except:
|
||||
error_detail = f"HTTP {response.status_code}"
|
||||
# 检查错误
|
||||
if isinstance(result, dict) and result.get('error'):
|
||||
raise HTTPException(status_code=400, detail=result['error'])
|
||||
|
||||
raise HTTPException(status_code=response.status_code, detail=error_detail)
|
||||
message = result.get('message', {})
|
||||
if isinstance(message, dict) and message.get('error'):
|
||||
raise HTTPException(status_code=400, detail=message['error'])
|
||||
|
||||
# 成功响应
|
||||
app_name = message.get('name', 'unknown') if isinstance(message, dict) else result.get('message', 'unknown')
|
||||
return {"success": True, "message": f"应用发布成功,应用名称: {app_name}"}
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user