优化local_app_installer.py
This commit is contained in:
parent
73f669d170
commit
a9cc8d950f
@ -25,6 +25,7 @@ from jingrow.utils.auth import get_jingrow_cloud_url, get_jingrow_cloud_api_head
|
||||
from jingrow.utils.export_app_package import export_app_package_from_local
|
||||
from jingrow.config import Config
|
||||
from jingrow.utils.app_manager import update_apps_txt
|
||||
import jingrow
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
@ -122,8 +123,7 @@ async def install_app_from_upload(
|
||||
# 对齐扫描安装的执行链
|
||||
try:
|
||||
# 1. 添加到 Local Installed Apps PageType
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
pagetype_result = get_single_pagetype("Local Installed Apps")
|
||||
pagetype_result = jingrow.get_single("Local Installed Apps")
|
||||
if pagetype_result.get('success'):
|
||||
config = pagetype_result.get('config', {})
|
||||
apps_list = config.get('local_installed_apps', [])
|
||||
@ -200,10 +200,8 @@ async def install_app_from_upload(
|
||||
async def check_app_exists(app_name: str):
|
||||
"""检查应用或扩展包是否已安装"""
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype, get_record_list
|
||||
|
||||
# 1. 检查应用是否已安装
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
|
||||
if result.get('success'):
|
||||
config = result.get('config', {})
|
||||
@ -214,12 +212,11 @@ async def check_app_exists(app_name: str):
|
||||
return {'exists': True, 'installed': True, 'type': 'app'}
|
||||
|
||||
# 2. 检查扩展包是否已安装(通过查询Package PageType)
|
||||
package_result = get_record_list("Package", filters=[["name", "=", app_name]], limit=1)
|
||||
package_data = jingrow.get_list("Package", filters=[["name", "=", app_name]], limit=1)
|
||||
|
||||
if package_result.get('success') and package_result.get('data'):
|
||||
if package_data:
|
||||
# 如果找到了记录
|
||||
if len(package_result.get('data', [])) > 0:
|
||||
return {'exists': True, 'installed': False, 'type': 'package'}
|
||||
return {'exists': True, 'installed': False, 'type': 'package'}
|
||||
|
||||
return {'exists': False, 'installed': False}
|
||||
except Exception as e:
|
||||
@ -230,12 +227,10 @@ async def check_app_exists(app_name: str):
|
||||
async def get_installed_app_names():
|
||||
"""获取所有已安装的应用名称列表"""
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype, get_record_list
|
||||
|
||||
installed = set()
|
||||
|
||||
# 从 Local Installed Apps 获取应用列表
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
if result.get('success'):
|
||||
config = result.get('config', {})
|
||||
local_installed_apps = config.get('local_installed_apps', [])
|
||||
@ -245,12 +240,11 @@ async def get_installed_app_names():
|
||||
installed.add(app_name.lower())
|
||||
|
||||
# 从 Package PageType 获取扩展包列表
|
||||
package_result = get_record_list("Package", fields=["name"], limit=1000)
|
||||
if package_result.get('success') and package_result.get('data'):
|
||||
for pkg in package_result.get('data', []):
|
||||
pkg_name = pkg.get('name', '')
|
||||
if pkg_name:
|
||||
installed.add(pkg_name.lower())
|
||||
package_data = jingrow.get_list("Package", fields=["name"], limit=1000)
|
||||
for pkg in package_data:
|
||||
pkg_name = pkg.get('name', '')
|
||||
if pkg_name:
|
||||
installed.add(pkg_name.lower())
|
||||
|
||||
return {'success': True, 'apps': list(installed)}
|
||||
except Exception as e:
|
||||
@ -266,8 +260,7 @@ async def get_local_installed_apps(request: Request):
|
||||
apps_dir = root / "apps"
|
||||
|
||||
# 获取已安装的App列表 - 通过get_single API获取
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
installed_names = set()
|
||||
if result.get('success'):
|
||||
config = result.get('config', {})
|
||||
@ -364,8 +357,7 @@ async def install_local_app(request: Request, app_name: str):
|
||||
backend_dir = app_dir
|
||||
|
||||
# 检查是否已经安装 - 通过get_single API检查
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
if result.get('success'):
|
||||
config = result.get('config', {})
|
||||
local_installed_apps = config.get('local_installed_apps', [])
|
||||
@ -375,10 +367,8 @@ async def install_local_app(request: Request, app_name: str):
|
||||
|
||||
# 将App信息添加到Local Installed Apps PageType
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
|
||||
# 获取当前应用列表
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
if result.get('success'):
|
||||
config = result.get('config', {})
|
||||
apps_list = config.get('local_installed_apps', [])
|
||||
@ -448,9 +438,7 @@ async def ensure_jingrow_registered():
|
||||
return
|
||||
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
if not result.get('success'):
|
||||
return
|
||||
|
||||
@ -475,9 +463,7 @@ async def get_installed_apps(request: Request):
|
||||
await ensure_jingrow_registered()
|
||||
|
||||
# 通过get_single API获取Local Installed Apps数据
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
|
||||
if not result.get('success'):
|
||||
return {
|
||||
@ -585,8 +571,7 @@ async def install_from_git(repo_url: str = Form(...)):
|
||||
|
||||
if app_dir:
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
pagetype_result = get_single_pagetype("Local Installed Apps")
|
||||
pagetype_result = jingrow.get_single("Local Installed Apps")
|
||||
apps_list = pagetype_result.get('config', {}).get('local_installed_apps', []) if pagetype_result.get('success') else []
|
||||
|
||||
app_exists = False
|
||||
@ -670,8 +655,7 @@ async def install_from_url(url: str = Form(...)):
|
||||
# 对齐扫描安装的执行链
|
||||
try:
|
||||
# 1. 添加到 Local Installed Apps PageType
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
pagetype_result = get_single_pagetype("Local Installed Apps")
|
||||
pagetype_result = jingrow.get_single("Local Installed Apps")
|
||||
if pagetype_result.get('success'):
|
||||
config = pagetype_result.get('config', {})
|
||||
apps_list = config.get('local_installed_apps', [])
|
||||
@ -901,10 +885,8 @@ async def _remove_from_database(app_name: str) -> Dict[str, Any]:
|
||||
"""从数据库中删除应用记录"""
|
||||
try:
|
||||
# 使用API方式操作数据库
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype
|
||||
|
||||
# 获取当前数据
|
||||
result = get_single_pagetype("Local Installed Apps")
|
||||
result = jingrow.get_single("Local Installed Apps")
|
||||
if not result.get('success'):
|
||||
return {'success': True, 'message': '未找到Local Installed Apps记录'}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user