修复从git仓库无法安装扩展包的问题
This commit is contained in:
parent
f042823922
commit
044b5379b7
@ -545,7 +545,9 @@ async def install_from_git(repo_url: str = Form(...)):
|
||||
# 判断是扩展包还是独立应用
|
||||
if not has_hooks:
|
||||
# 作为扩展包安装到 jingrow 应用内部
|
||||
result = install_package(str(clone_dir), package_info['data'])
|
||||
# 注意:package_info['data']['root_dir'] 已经是 git clone 后进入仓库目录的路径
|
||||
# 但我们传给 install_package 的 temp_dir 应该是仓库内容的实际路径
|
||||
result = install_package(package_info['data']['root_dir'], package_info['data'])
|
||||
shutil.rmtree(clone_dir, ignore_errors=True)
|
||||
return result
|
||||
else:
|
||||
|
||||
@ -71,8 +71,26 @@ def extract_package(zip_path: str) -> Dict[str, Any]:
|
||||
def analyze_package(temp_dir: str) -> Dict[str, Any]:
|
||||
"""分析安装包结构"""
|
||||
# 查找根目录
|
||||
if not os.path.exists(temp_dir):
|
||||
return {'success': False, 'error': f'目录不存在: {temp_dir}'}
|
||||
|
||||
root_items = os.listdir(temp_dir)
|
||||
root_dir = os.path.join(temp_dir, root_items[0]) if len(root_items) == 1 and os.path.isdir(os.path.join(temp_dir, root_items[0])) else temp_dir
|
||||
print(f"[DEBUG] analyze_package - temp_dir: {temp_dir}")
|
||||
print(f"[DEBUG] analyze_package - root_items: {root_items}")
|
||||
|
||||
if not root_items:
|
||||
return {'success': False, 'error': '目录为空'}
|
||||
|
||||
# 对于 git clone 的目录,跳过 .git,进入仓库名目录
|
||||
# 找到一个不是 .git 的目录作为 root_dir
|
||||
root_dir = temp_dir
|
||||
for item in root_items:
|
||||
item_path = os.path.join(temp_dir, item)
|
||||
if os.path.isdir(item_path) and item != '.git':
|
||||
root_dir = item_path
|
||||
break
|
||||
|
||||
print(f"[DEBUG] analyze_package - resolved root_dir: {root_dir}")
|
||||
|
||||
package_info = {
|
||||
'app_name': os.path.basename(root_dir),
|
||||
@ -385,6 +403,12 @@ def install_package(temp_dir: str, package_info: Dict[str, Any]) -> Dict[str, An
|
||||
root_dir = package_info.get('root_dir', temp_dir)
|
||||
app_name = package_info.get('app_name')
|
||||
|
||||
# 调试日志
|
||||
print(f"[DEBUG] install_package - temp_dir: {temp_dir}")
|
||||
print(f"[DEBUG] install_package - root_dir: {root_dir}")
|
||||
print(f"[DEBUG] install_package - app_name: {app_name}")
|
||||
print(f"[DEBUG] install_package - package_info keys: {list(package_info.keys())}")
|
||||
|
||||
# 获取 jingrow 应用目录
|
||||
apps_dir, _ = get_app_directories()
|
||||
jingrow_backend_dir = apps_dir / "jingrow" / "jingrow"
|
||||
@ -392,9 +416,8 @@ def install_package(temp_dir: str, package_info: Dict[str, Any]) -> Dict[str, An
|
||||
if not jingrow_backend_dir.exists():
|
||||
return {'success': False, 'error': '找不到 jingrow 应用目录'}
|
||||
|
||||
# 检查是否有 app_name 子目录
|
||||
inner_app_dir = os.path.join(root_dir, app_name)
|
||||
source_dir = inner_app_dir if os.path.exists(inner_app_dir) and os.path.isdir(inner_app_dir) else root_dir
|
||||
# 直接使用 root_dir 作为源目录(扩展包只包含模块目录,不需要额外的目录层级)
|
||||
source_dir = root_dir
|
||||
|
||||
# 先同步到数据库
|
||||
try:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user