|
|
@@ -220,3 +220,33 @@ async def save_db(db, username, password, email, user_id, app_id, app_type):
|
|
|
if not user_id:
|
|
|
raise Exception("Failed to register with app")
|
|
|
print({"msg": "User registered successfully", "userFlag": user_id})
|
|
|
+
|
|
|
+
|
|
|
+async def admin_account_sync(db):
|
|
|
+ agent_list = []
|
|
|
+ with open(os.path.join(ENV_CONF_PATH, "default_agent_conf.json"), 'r', encoding='utf-8') as file:
|
|
|
+ # 加载JSON数据
|
|
|
+ agent_dict = json.load(file)
|
|
|
+ agent_list = agent_dict.get("basic", [])
|
|
|
+ user = db.query(UserModel).filter_by(permission="admin").first()
|
|
|
+ for agent in agent_list:
|
|
|
+ dialog = db.query(DialogModel).filter(DialogModel.id == agent["id"]).first()
|
|
|
+ if dialog:
|
|
|
+ try:
|
|
|
+ dialog.name = agent["name"]
|
|
|
+ dialog.description = agent["description"]
|
|
|
+ dialog.icon = agent["icon"]
|
|
|
+ db.commit()
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(e)
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ dialog = DialogModel(id=agent["id"], name=agent["name"], description=agent["description"],
|
|
|
+ icon=agent["icon"], tenant_id=user.id if user else "", dialog_type="3",
|
|
|
+ agent_id=agent["id"])
|
|
|
+ db.add(dialog)
|
|
|
+ db.commit()
|
|
|
+ db.refresh(dialog)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ db.rollback()
|