复安装本地版app时无法正确导入pagetype和module到saas端的问题
This commit is contained in:
parent
7fbd495891
commit
ac4eb3bd0f
@ -803,8 +803,6 @@
|
|||||||
"Uploading file...": "上传文件中...",
|
"Uploading file...": "上传文件中...",
|
||||||
"Installation completed!": "安装完成!",
|
"Installation completed!": "安装完成!",
|
||||||
"Installation failed!": "安装失败!",
|
"Installation failed!": "安装失败!",
|
||||||
"Installation failed": "安装失败",
|
|
||||||
"Upload failed": "上传失败",
|
|
||||||
"App Details": "应用详情",
|
"App Details": "应用详情",
|
||||||
"Version": "版本",
|
"Version": "版本",
|
||||||
"No description": "无描述",
|
"No description": "无描述",
|
||||||
@ -819,8 +817,6 @@
|
|||||||
"Size": "大小",
|
"Size": "大小",
|
||||||
"Extension Package": "扩展包",
|
"Extension Package": "扩展包",
|
||||||
"Failed to save package": "保存应用包失败",
|
"Failed to save package": "保存应用包失败",
|
||||||
"Saving package...": "正在保存应用包...",
|
|
||||||
"Installing package...": "正在安装应用包...",
|
|
||||||
"Installing extension package...": "正在安装扩展包...",
|
"Installing extension package...": "正在安装扩展包...",
|
||||||
"Failed to load local apps": "加载本地应用失败",
|
"Failed to load local apps": "加载本地应用失败",
|
||||||
"Failed to install app": "安装应用失败",
|
"Failed to install app": "安装应用失败",
|
||||||
|
|||||||
@ -33,6 +33,57 @@ INSTALLED_APP_TYPE = 'installed'
|
|||||||
_jingrow_registered_cache = None
|
_jingrow_registered_cache = None
|
||||||
|
|
||||||
|
|
||||||
|
def _import_app_package_and_pagetypes(app_name: str, install_result: Dict[str, Any]) -> None:
|
||||||
|
"""直接导入应用的 Package 和 PageTypes 到数据库"""
|
||||||
|
try:
|
||||||
|
# 从安装结果获取路径
|
||||||
|
backend_result = install_result.get('backend_result', {})
|
||||||
|
app_dir = backend_result.get('app_dir')
|
||||||
|
|
||||||
|
if not app_dir:
|
||||||
|
# 计算应用路径
|
||||||
|
current = Path(__file__).resolve()
|
||||||
|
root = current.parents[4]
|
||||||
|
apps_dir = root / "apps"
|
||||||
|
backend_dir = apps_dir / app_name / app_name
|
||||||
|
if not backend_dir.exists():
|
||||||
|
backend_dir = apps_dir / app_name
|
||||||
|
app_dir = str(backend_dir)
|
||||||
|
else:
|
||||||
|
# 构建后端代码目录路径
|
||||||
|
backend_dir = Path(app_dir) / app_name
|
||||||
|
if not backend_dir.exists():
|
||||||
|
backend_dir = Path(app_dir)
|
||||||
|
app_dir = str(backend_dir)
|
||||||
|
|
||||||
|
if not os.path.exists(app_dir):
|
||||||
|
log_info(f"应用目录不存在: {app_dir},跳过导入")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 调用 jingrow whitelist API 导入
|
||||||
|
try:
|
||||||
|
api_url = f"{Config.jingrow_server_url}/api/action/jingrow.ai.utils.jlocal.sync_app_files"
|
||||||
|
headers = get_jingrow_api_headers()
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
api_url,
|
||||||
|
json={'app_name': app_name, 'app_path': app_dir, 'force': True},
|
||||||
|
headers=headers,
|
||||||
|
timeout=60
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
result_data = response.json()
|
||||||
|
log_info(f"导入结果: {result_data}")
|
||||||
|
else:
|
||||||
|
log_error(f"导入失败: HTTP {response.status_code}")
|
||||||
|
except Exception as api_error:
|
||||||
|
log_error(f"调用导入 API 失败: {str(api_error)}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
log_error(f"导入应用数据失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
@router.post("/jingrow/install/upload")
|
@router.post("/jingrow/install/upload")
|
||||||
async def install_app_from_upload(
|
async def install_app_from_upload(
|
||||||
request: Request,
|
request: Request,
|
||||||
@ -58,7 +109,17 @@ async def install_app_from_upload(
|
|||||||
result = install_app(temp_file.name, app_name)
|
result = install_app(temp_file.name, app_name)
|
||||||
|
|
||||||
if result.get('success'):
|
if result.get('success'):
|
||||||
log_info(f"应用安装成功: {result.get('app_name')}")
|
app_name_result = result.get('app_name')
|
||||||
|
log_info(f"应用安装成功: {app_name_result}")
|
||||||
|
|
||||||
|
# 导入 Package 和 PageTypes 到数据库
|
||||||
|
try:
|
||||||
|
_import_app_package_and_pagetypes(app_name_result, result)
|
||||||
|
log_info(f"应用 {app_name_result} 的 Package 和 PageTypes 已导入")
|
||||||
|
except Exception as import_error:
|
||||||
|
log_error(f"导入 Package 和 PageTypes 失败: {str(import_error)}")
|
||||||
|
# 不阻止安装成功,只是警告
|
||||||
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=400, detail=result.get('error'))
|
raise HTTPException(status_code=400, detail=result.get('error'))
|
||||||
@ -171,15 +232,20 @@ async def get_local_apps(request: Request):
|
|||||||
async def install_local_app(request: Request, app_name: str):
|
async def install_local_app(request: Request, app_name: str):
|
||||||
"""安装本地App"""
|
"""安装本地App"""
|
||||||
try:
|
try:
|
||||||
# 获取应用目录路径 - 修正路径
|
# 获取应用目录路径
|
||||||
current = Path(__file__).resolve()
|
current = Path(__file__).resolve()
|
||||||
root = current.parents[4] # 调整路径层级
|
root = current.parents[4]
|
||||||
apps_dir = root / "apps" # 新的apps目录
|
apps_dir = root / "apps"
|
||||||
app_dir = apps_dir / app_name
|
app_dir = apps_dir / app_name
|
||||||
|
backend_dir = app_dir / app_name # 后端代码目录
|
||||||
|
|
||||||
if not app_dir.exists():
|
if not app_dir.exists():
|
||||||
raise HTTPException(status_code=404, detail=f"App '{app_name}' not found")
|
raise HTTPException(status_code=404, detail=f"App '{app_name}' not found")
|
||||||
|
|
||||||
|
if not backend_dir.exists():
|
||||||
|
log_info(f"后端目录不存在: {backend_dir},跳过导入")
|
||||||
|
backend_dir = app_dir # 使用应用根目录
|
||||||
|
|
||||||
# 检查是否已经安装 - 通过get_single API检查
|
# 检查是否已经安装 - 通过get_single API检查
|
||||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||||
result = get_single_pagetype("Local Installed Apps")
|
result = get_single_pagetype("Local Installed Apps")
|
||||||
@ -218,6 +284,24 @@ async def install_local_app(request: Request, app_name: str):
|
|||||||
|
|
||||||
if await _update_local_installed_apps(apps_list):
|
if await _update_local_installed_apps(apps_list):
|
||||||
log_info(f"应用 {app_name} 已注册到数据库")
|
log_info(f"应用 {app_name} 已注册到数据库")
|
||||||
|
|
||||||
|
# 同步应用到数据库(导入 Package 和 PageTypes)
|
||||||
|
try:
|
||||||
|
api_url = f"{Config.jingrow_server_url}/api/action/jingrow.ai.utils.jlocal.sync_app_files"
|
||||||
|
response = requests.post(
|
||||||
|
api_url,
|
||||||
|
json={'app_name': app_name, 'app_path': str(backend_dir), 'force': True},
|
||||||
|
headers=get_jingrow_api_headers(),
|
||||||
|
timeout=60
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
log_info(f"应用 {app_name} 的 Package 和 PageTypes 已成功同步到数据库")
|
||||||
|
else:
|
||||||
|
log_error(f"同步应用 {app_name} 失败: HTTP {response.status_code}")
|
||||||
|
except Exception as sync_error:
|
||||||
|
log_error(f"同步应用 {app_name} 时出错: {str(sync_error)}")
|
||||||
|
# 不阻止安装成功,只是记录错误
|
||||||
else:
|
else:
|
||||||
log_error("更新数据库失败")
|
log_error("更新数据库失败")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user