卸载app时自动删除对应的app目录

This commit is contained in:
jingrow 2025-10-26 02:01:03 +08:00
parent 7d75bb22fa
commit 01db396809
3 changed files with 11 additions and 75 deletions

View File

@ -117,23 +117,6 @@ const refreshApps = () => {
loadInstalledApps()
}
const showAppDetail = async (app: any) => {
try {
const response = await axios.get(`/jingrow/app-info/${app.name}`, {
headers: get_session_api_headers()
})
if (response.data.success) {
selectedApp.value = { ...app, ...response.data.data }
showDetailModal.value = true
} else {
message.error(response.data.error || t('Failed to load app details'))
}
} catch (error: any) {
console.error('Load app detail error:', error)
message.error(error.response?.data?.error || t('Failed to load app details'))
}
}
const uninstallApp = async (app: any) => {
//
@ -171,13 +154,6 @@ const uninstallApp = async (app: any) => {
})
}
const getAppTypeText = (type: string) => {
switch (type) {
case 'frontend': return t('Frontend Only')
case 'both': return t('Full Stack')
default: return t('Backend Only')
}
}
//
onMounted(() => {

View File

@ -333,7 +333,7 @@ async def get_installed_apps(request: Request):
@router.post("/jingrow/uninstall/{app_name}")
async def uninstall_app(request: Request, app_name: str):
"""卸载应用 - 直接删除整个app目录"""
try:
log_info(f"开始卸载应用: {app_name}")
@ -341,64 +341,24 @@ async def uninstall_app(request: Request, app_name: str):
if app_name == JINGROW_APP_NAME:
raise HTTPException(status_code=403, detail=f"系统应用 '{JINGROW_APP_NAME}' 不允许卸载")
# 检查应用是否存在(文件系统或数据库)
backend_dir, frontend_dir = get_app_directories()
# 检查多种可能的目录结构
possible_backend_dirs = [
backend_dir / app_name / app_name, # apps/myapp/myapp/
backend_dir / app_name / app_name / app_name, # apps/myapp/myapp/myapp/
]
frontend_app_dir = frontend_dir / app_name / "frontend"
# 获取应用目录
apps_dir, _ = get_app_directories()
app_dir = apps_dir / app_name
# 找到实际存在的后端目录
backend_app_dir = None
for possible_dir in possible_backend_dirs:
if possible_dir.exists():
backend_app_dir = possible_dir
break
# 检查数据库中是否有记录
from jingrow.utils.jingrow_api import get_single_pagetype
db_result = get_single_pagetype("Local Installed Apps")
app_exists_in_db = False
if db_result.get('success'):
config = db_result.get('config', {})
local_installed_apps = config.get('local_installed_apps', [])
app_exists_in_db = any(app.get('app_name', '') == app_name for app in local_installed_apps)
# 如果文件不存在且数据库也没有记录,则报错
if not backend_app_dir and not frontend_app_dir.exists() and not app_exists_in_db:
# 检查应用是否存在
if not app_dir.exists():
raise HTTPException(status_code=404, detail=f"应用 {app_name} 不存在")
# 删除后端文件
backend_result = {'success': True, 'message': '无后端文件'}
if backend_app_dir:
try:
shutil.rmtree(backend_app_dir)
backend_result = {'success': True, 'message': '后端文件删除成功'}
log_info(f"后端文件删除成功: {backend_app_dir}")
except Exception as e:
backend_result = {'success': False, 'error': f'后端文件删除失败: {str(e)}'}
# 删除前端文件
frontend_result = {'success': True, 'message': '无前端文件'}
if frontend_app_dir.exists():
try:
shutil.rmtree(frontend_app_dir)
frontend_result = {'success': True, 'message': '前端文件删除成功'}
log_info(f"前端文件删除成功: {frontend_app_dir}")
except Exception as e:
frontend_result = {'success': False, 'error': f'前端文件删除失败: {str(e)}'}
# 删除整个app目录
shutil.rmtree(app_dir)
log_info(f"应用目录删除成功: {app_dir}")
# 从数据库中删除记录
db_result = await _remove_from_database(app_name)
return {
'success': True,
'message': f'应用 {app_name} 卸载成功',
'backend_result': backend_result,
'frontend_result': frontend_result,
'db_result': db_result
'message': f'应用 {app_name} 卸载成功'
}
except HTTPException:

View File

@ -33,7 +33,7 @@ def handle_errors(func):
def get_app_directories():
"""获取应用目录路径"""
project_root = Path(__file__).resolve().parents[6]
project_root = Path(__file__).resolve().parents[4]
apps_dir = project_root / "apps"
apps_dir.mkdir(parents=True, exist_ok=True)