| | |
| | | |
| | | |
| | | from Log import logger |
| | | from app.config.agent_base_url import RG_APP_TOKEN_LIST, RG_APP_NEW_TOKEN |
| | | # from app.api import pwd_context |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW, smart_server, chat_server, workflow_server, TMP_DICT |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW, smart_server, chat_server, workflow_server, TMP_DICT, \ |
| | | rg_api_token |
| | | from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \ |
| | | cipher_suite, UserTokenModel |
| | | cipher_suite, UserTokenModel, ApiTokenModel |
| | | from app.service.auth import UserAppDao |
| | | from app.service.bisheng import BishengService |
| | | from app.service.difyService import DifyService |
| | | from app.service.ragflow import RagflowService |
| | | from app.service.service_token import get_new_token |
| | | from app.service.v2.app_driver.chat_data import ChatBaseApply |
| | | from app.service.v2.app_register import AppRegisterDao |
| | | from app.config.config import settings |
| | | from app.utils.password_handle import generate_password, password_encrypted, password_decrypted |
| | |
| | | # await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k) |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |
| | | |
| | | |
| | | async def sync_rg_api_token(db): |
| | | token = "" |
| | | try: |
| | | app_token = db.query(ApiTokenModel).filter_by(app_id=rg_api_token).first() |
| | | if app_token: |
| | | print("rg_api_token: 已经存在!") |
| | | return |
| | | user_token = db.query(UserTokenModel).filter(UserTokenModel.id == chat_server).first() |
| | | chat = ChatBaseApply() |
| | | token_list_url = f"{settings.fwr_base_url}{RG_APP_TOKEN_LIST}" |
| | | token_list = await chat.chat_get(token_list_url, {}, await chat.get_chat_headers(user_token.access_token)) |
| | | if token_list and token_list.get("code") == 0: |
| | | if len(token_list.get("data", [])) == 0: |
| | | print("rg_api_token: 创建成功!") |
| | | new_token_url = f"{settings.fwr_base_url}{RG_APP_NEW_TOKEN}" |
| | | new_token = await chat.chat_post(new_token_url, {}, await chat.get_chat_headers(user_token.access_token)) |
| | | if new_token and new_token.get("code") == 0: |
| | | token = new_token.get("data", {}).get("token") |
| | | else: |
| | | token = token_list.get("data")[0].get("token") |
| | | print("rg_api_token: 已有token!") |
| | | if token: |
| | | |
| | | db.add(ApiTokenModel(id=rg_api_token, app_id=rg_api_token, type="platform", token=token)) |
| | | db.commit() |
| | | print("rg_api_token: 更新成功!") |
| | | |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |