diff --git a/jcloud/api/local_app.py b/jcloud/api/local_app.py index 724215b..fbe963e 100644 --- a/jcloud/api/local_app.py +++ b/jcloud/api/local_app.py @@ -112,7 +112,7 @@ def get_local_app(name): """获取本地应用详情""" if not jingrow.db.exists("Local App", name): - jingrow.throw("Local App not found") + return {"success": False, "message": "应用不存在"} app = jingrow.get_pg("Local App", name) @@ -177,21 +177,31 @@ def update_local_app(name, app_data): """更新本地应用""" if not jingrow.db.exists("Local App", name): - jingrow.throw("Local App not found") + return {"success": False, "message": "应用不存在"} app = jingrow.get_pg("Local App", name) + # 解析 JSON 数据 if isinstance(app_data, str): - import json - app_data = json.loads(app_data) + try: + import json + app_data = json.loads(app_data) + except json.JSONDecodeError: + return {"success": False, "message": "JSON 数据格式错误"} # 更新字段 + updated_fields = [] for field, value in app_data.items(): if hasattr(app, field): setattr(app, field, value) + updated_fields.append(field) + + # 检查是否有字段被更新 + if not updated_fields: + return {"success": False, "message": "没有有效的字段被更新"} app.save() - return app.name + return {"success": True, "name": app.name, "updated_fields": updated_fields, "message": "应用更新成功"} @dashboard_whitelist() @@ -199,12 +209,12 @@ def delete_local_app(name): """删除本地应用""" if not jingrow.db.exists("Local App", name): - jingrow.throw("Local App not found") + return {"success": False, "message": "应用不存在"} app = jingrow.get_pg("Local App", name) app.delete() - return "Local App deleted successfully" + return {"success": True, "message": "应用删除成功"} @jingrow.whitelist(allow_guest=True)