From 9c8fb19ed8aabaa153fc9623ee62d4f09ecde60f Mon Sep 17 00:00:00 2001 From: jingrow Date: Sun, 26 Oct 2025 22:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E8=B0=83=E8=AF=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/views/dev/AppInstaller.vue | 14 +------ .../jingrow/api/local_app_installer.py | 38 ++++--------------- apps/jingrow/jingrow/utils/app_installer.py | 21 +--------- 3 files changed, 11 insertions(+), 62 deletions(-) diff --git a/apps/jingrow/frontend/src/views/dev/AppInstaller.vue b/apps/jingrow/frontend/src/views/dev/AppInstaller.vue index 725c9af..edf6c9a 100644 --- a/apps/jingrow/frontend/src/views/dev/AppInstaller.vue +++ b/apps/jingrow/frontend/src/views/dev/AppInstaller.vue @@ -64,14 +64,11 @@ {{ t('Size') }}: {{ formatFileSize(fileList[0].file.size) }} - - {{ t('Extension Package') }} - -
+
('info') const showProgressModal = ref(false) -const isExtensionFile = ref(false) const localApps = ref([]) const loadingLocalApps = ref(false) @@ -222,11 +218,6 @@ const beforeUpload = (data: { file: UploadFileInfo }) => { const handleFileChange = (options: { fileList: UploadFileInfo[] }) => { fileList.value = options.fileList - - // 移除对扩展包的特殊处理,统一使用应用安装流程 - if (fileList.value.length > 0) { - isExtensionFile.value = false - } } const customUpload = async (_options: any) => { @@ -310,7 +301,6 @@ const startUpload = async () => { const clearFiles = () => { fileList.value = [] appName.value = '' - isExtensionFile.value = false uploadRef.value?.clear() } diff --git a/apps/jingrow/jingrow/api/local_app_installer.py b/apps/jingrow/jingrow/api/local_app_installer.py index 0a92ea2..bba65b6 100644 --- a/apps/jingrow/jingrow/api/local_app_installer.py +++ b/apps/jingrow/jingrow/api/local_app_installer.py @@ -104,13 +104,9 @@ async def install_app_from_upload( # 保存上传的文件到项目tmp目录 content = await file.read() - log_info(f"文件大小: {len(content)} 字节") - with open(temp_file_path, 'wb') as f: f.write(content) - log_info(f"文件已保存到: {temp_file_path}, 存在: {temp_file_path.exists()}, 大小: {temp_file_path.stat().st_size if temp_file_path.exists() else 0}") - # 统一使用 install_app 函数处理所有格式 try: result = install_app(str(temp_file_path), app_name) @@ -148,14 +144,10 @@ async def install_app_from_upload( }) # 更新数据库 - if await _update_local_installed_apps(apps_list): - log_info(f"已更新 Local Installed Apps: {app_name_result}") - - # 2. 调用 sync_app_files 同步文件到数据库(pagetype, package, module) - log_info(f"准备同步应用文件: app_name={app_name_result}, app_dir={app_dir}") + await _update_local_installed_apps(apps_list) + # 2. 调用 sync_app_files 同步文件到数据库 if app_dir: - # 计算应用的后端目录 current = Path(__file__).resolve() root = current.parents[4] apps_dir = root / "apps" @@ -163,47 +155,31 @@ async def install_app_from_upload( if not backend_dir.exists(): backend_dir = apps_dir / app_name_result - log_info(f"后端目录: {backend_dir}, 存在: {backend_dir.exists()}") - if backend_dir.exists(): try: api_url = f"{Config.jingrow_server_url}/api/action/jingrow.ai.utils.jlocal.sync_app_files" - log_info(f"调用 sync_app_files API: {api_url}, 参数: app_name={app_name_result}, app_path={str(backend_dir)}") - response = requests.post( + requests.post( api_url, json={'app_name': app_name_result, 'app_path': str(backend_dir), 'force': True}, headers=get_jingrow_api_headers(), timeout=60 ) - log_info(f"sync_app_files 响应: status={response.status_code}, body={response.text}") - if response.status_code == 200: - log_info(f"已同步应用文件到数据库: {app_name_result}, 响应: {response.json()}") - else: - log_error(f"同步应用文件失败: HTTP {response.status_code}, {response.text}") except Exception as e: - import traceback - log_error(f"同步应用文件异常: {str(e)}, {traceback.format_exc()}") - else: - log_error(f"后端目录不存在: {backend_dir}") - else: - log_error(f"app_dir 为空,无法同步文件") + log_error(f"同步应用文件失败: {str(e)}") except Exception as e: log_error(f"更新数据库失败: {str(e)}") return result else: - error_msg = result.get('error', '未知错误') - log_error(f"安装失败: {error_msg}") - raise HTTPException(status_code=400, detail=error_msg) + raise HTTPException(status_code=400, detail=result.get('error', '安装失败')) finally: # 清理上传的文件 try: if temp_file_path.exists(): os.unlink(temp_file_path) - log_info(f"已删除临时文件: {temp_file_path}") - except Exception as e: - log_error(f"删除临时文件失败: {e}") + except Exception: + pass except HTTPException: raise diff --git a/apps/jingrow/jingrow/utils/app_installer.py b/apps/jingrow/jingrow/utils/app_installer.py index c092d5b..e1b1a4d 100644 --- a/apps/jingrow/jingrow/utils/app_installer.py +++ b/apps/jingrow/jingrow/utils/app_installer.py @@ -140,8 +140,6 @@ def install_files(temp_dir: str, app_name: str, package_info: Dict[str, Any], is # 检查 root_dir 下是否有 app_name 子目录(解压后可能有两层app_name) inner_app_dir = os.path.join(root_dir, app_name) if os.path.exists(inner_app_dir) and os.path.isdir(inner_app_dir): - # 如果存在内层 app_name 目录,复制它 - log_info(f"复制内层应用目录: {inner_app_dir} -> {backend_dir}") for item in os.listdir(inner_app_dir): src = os.path.join(inner_app_dir, item) dst = backend_dir / item @@ -150,10 +148,7 @@ def install_files(temp_dir: str, app_name: str, package_info: Dict[str, Any], is else: shutil.copy2(src, dst) else: - # 否则直接复制 root_dir - log_info(f"复制应用目录: {root_dir} -> {backend_dir}") for item in os.listdir(root_dir): - # 跳过不需要的文件 if item in ['__pycache__', '.git']: continue src = os.path.join(root_dir, item) @@ -170,7 +165,6 @@ def install_files(temp_dir: str, app_name: str, package_info: Dict[str, Any], is frontend_src = os.path.join(root_dir, "frontend") if os.path.exists(frontend_src): - log_info(f"复制前端目录: {frontend_src} -> {frontend_dir}") for item in os.listdir(frontend_src): src = os.path.join(frontend_src, item) dst = frontend_dir / item @@ -298,34 +292,26 @@ def install_app(uploaded_file_path: str, app_name: str = None) -> Dict[str, Any] analyze_result = analyze_package(temp_dir) if not analyze_result.get('success'): cleanup_temp_dir(temp_dir) - log_error(f"分析包失败: {analyze_result.get('error')}") return analyze_result package_info = analyze_result['data'] - log_info(f"包信息: {package_info}") # 确定应用名称 if not app_name: app_name = package_info.get('app_name') if not app_name: cleanup_temp_dir(temp_dir) - log_error(f"无法识别应用名称,包信息: {package_info}") return {'success': False, 'error': '无法识别应用名称'} - log_info(f"应用名称: {app_name}") - # 如果应用已安装,先删除旧版本(允许覆盖安装) if is_app_installed(app_name): - log_info(f"应用 {app_name} 已存在,将覆盖安装") apps_dir, _ = get_app_directories() app_dir = apps_dir / app_name try: if app_dir.exists(): shutil.rmtree(app_dir) - log_info(f"已删除旧版本应用: {app_dir}") except Exception as e: cleanup_temp_dir(temp_dir) - log_error(f"删除旧应用失败: {e}") return {'success': False, 'error': f'删除旧应用失败: {str(e)}'} # 安装后端文件 @@ -345,20 +331,17 @@ def install_app(uploaded_file_path: str, app_name: str = None) -> Dict[str, Any] return frontend_result # 记录安装信息 - db_result = record_installation(app_name, package_info, uploaded_file_path) + record_installation(app_name, package_info, uploaded_file_path) # 清理临时文件 cleanup_temp_dir(temp_dir) - - log_info(f"应用 {app_name} 安装成功") return { 'success': True, 'message': f'应用 {app_name} 安装成功', 'app_name': app_name, 'package_info': package_info, 'backend_result': backend_result, - 'frontend_result': frontend_result, - 'db_result': db_result + 'frontend_result': frontend_result } except Exception as e: