从git仓库安装app时更新为使用默认分支
This commit is contained in:
parent
46aac3eaf4
commit
f042823922
@ -278,8 +278,7 @@ async function performInstall() {
|
|||||||
installMessage.value = t('正在安装应用...')
|
installMessage.value = t('正在安装应用...')
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
repo_url: app.value.repository_url,
|
repo_url: app.value.repository_url
|
||||||
branch: app.value.branch || 'main'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
response = await axios.post('/jingrow/install-from-git', params, {
|
response = await axios.post('/jingrow/install-from-git', params, {
|
||||||
|
|||||||
@ -316,8 +316,7 @@ async function performInstall(app: any) {
|
|||||||
installMessage.value = t('正在安装应用...')
|
installMessage.value = t('正在安装应用...')
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
repo_url: app.repository_url,
|
repo_url: app.repository_url
|
||||||
branch: app.branch || 'main'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
response = await axios.post('/jingrow/install-from-git', params, {
|
response = await axios.post('/jingrow/install-from-git', params, {
|
||||||
|
|||||||
@ -503,7 +503,7 @@ async def get_installed_apps(request: Request):
|
|||||||
|
|
||||||
|
|
||||||
@router.post("/jingrow/install-from-git")
|
@router.post("/jingrow/install-from-git")
|
||||||
async def install_from_git(repo_url: str = Form(...), branch: str = Form('main')):
|
async def install_from_git(repo_url: str = Form(...)):
|
||||||
"""从 git 仓库克隆并安装应用或扩展包"""
|
"""从 git 仓库克隆并安装应用或扩展包"""
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -516,9 +516,9 @@ async def install_from_git(repo_url: str = Form(...), branch: str = Form('main')
|
|||||||
clone_dir = tmp_dir / f"git_clone_{uuid.uuid4().hex[:8]}"
|
clone_dir = tmp_dir / f"git_clone_{uuid.uuid4().hex[:8]}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 使用 git clone 克隆仓库
|
# 使用 git clone 克隆仓库(使用仓库默认分支)
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['git', 'clone', '-b', branch, repo_url, str(clone_dir)],
|
['git', 'clone', repo_url, str(clone_dir)],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=300
|
timeout=300
|
||||||
@ -529,17 +529,27 @@ async def install_from_git(repo_url: str = Form(...), branch: str = Form('main')
|
|||||||
raise HTTPException(status_code=400, detail=f"Git 克隆失败: {result.stderr}")
|
raise HTTPException(status_code=400, detail=f"Git 克隆失败: {result.stderr}")
|
||||||
|
|
||||||
# 直接使用克隆的目录进行分析和安装
|
# 直接使用克隆的目录进行分析和安装
|
||||||
from jingrow.utils.app_installer import analyze_package, install_files, is_app_installed
|
from jingrow.utils.app_installer import analyze_package, install_files, is_app_installed, install_package
|
||||||
|
|
||||||
# 分析包结构
|
# 分析包结构
|
||||||
package_info = analyze_package(str(clone_dir))
|
package_info = analyze_package(str(clone_dir))
|
||||||
if not package_info.get('success'):
|
if not package_info.get('success'):
|
||||||
raise HTTPException(status_code=400, detail=package_info.get('error', '无法识别应用'))
|
raise HTTPException(status_code=400, detail=package_info.get('error', '无法识别应用'))
|
||||||
|
|
||||||
|
has_hooks = package_info['data'].get('has_hooks', False)
|
||||||
app_name = package_info['data'].get('app_name')
|
app_name = package_info['data'].get('app_name')
|
||||||
|
|
||||||
if not app_name:
|
if not app_name:
|
||||||
raise HTTPException(status_code=400, detail='无法识别应用名称')
|
raise HTTPException(status_code=400, detail='无法识别应用名称')
|
||||||
|
|
||||||
|
# 判断是扩展包还是独立应用
|
||||||
|
if not has_hooks:
|
||||||
|
# 作为扩展包安装到 jingrow 应用内部
|
||||||
|
result = install_package(str(clone_dir), package_info['data'])
|
||||||
|
shutil.rmtree(clone_dir, ignore_errors=True)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
# 独立应用安装
|
||||||
# 如果应用已安装,先删除旧版本
|
# 如果应用已安装,先删除旧版本
|
||||||
if is_app_installed(app_name):
|
if is_app_installed(app_name):
|
||||||
apps_dir, _ = get_app_directories()
|
apps_dir, _ = get_app_directories()
|
||||||
@ -576,12 +586,12 @@ async def install_from_git(repo_url: str = Form(...), branch: str = Form('main')
|
|||||||
app_exists = False
|
app_exists = False
|
||||||
for app in apps_list:
|
for app in apps_list:
|
||||||
if app.get('app_name', '') == app_name:
|
if app.get('app_name', '') == app_name:
|
||||||
app.update({'app_version': '1.0.0', 'git_branch': branch, 'git_repo': repo_url})
|
app.update({'app_version': '1.0.0', 'git_repo': repo_url})
|
||||||
app_exists = True
|
app_exists = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not app_exists:
|
if not app_exists:
|
||||||
apps_list.append({'app_name': app_name, 'app_version': '1.0.0', 'git_branch': branch, 'git_repo': repo_url})
|
apps_list.append({'app_name': app_name, 'app_version': '1.0.0', 'git_repo': repo_url})
|
||||||
|
|
||||||
await _update_local_installed_apps(apps_list)
|
await _update_local_installed_apps(apps_list)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user