From 48e33c7fbd6969d05b2affda0321595d2d6b370a Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期一, 10 二月 2025 14:51:06 +0800
Subject: [PATCH] 增加ping機制

---
 app/service/v2/app_driver/chat_data.py |   48 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/app/service/v2/app_driver/chat_data.py b/app/service/v2/app_driver/chat_data.py
index ebfa63d..97939d2 100644
--- a/app/service/v2/app_driver/chat_data.py
+++ b/app/service/v2/app_driver/chat_data.py
@@ -1,12 +1,14 @@
 import json
 
+from app.config.config import settings
 # from Log import logger
 from app.service.v2.app_driver.chat_base import ChatBase
+from app.utils.rsa_crypto import RagflowCrypto
 
 
 class ChatBaseApply(ChatBase):
 
-    async def chat_parameters(self, url, params, headers):
+    async def chat_get(self, url, params, headers):
 
         res = await self.http_get(url, params, headers)
         if res.status_code == 200:
@@ -14,8 +16,43 @@
         else:
             return {}
 
+    async def chat_ping(self, url, params, headers):
+        res = await self.http_get(url, params, headers)
+        return res.status_code
 
 
+    async def chat_post(self, url, data, headers):
+
+        res = await self.http_post(url, data, headers)
+        if res.status_code == 200 or res.status_code == 201:
+            return res.json()
+        else:
+            return {}
+
+    async def chat_login(self, url, data, headers):
+
+        res = await self.http_post(url, data, headers)
+        if res.status_code == 200:
+            res_json = res.json()
+            authorization = res.headers.get('Authorization')
+            if authorization:
+                res_json["data"]["access_token"] = authorization
+            return res_json
+        else:
+            return {}
+
+
+    @staticmethod
+    async def password_encrypt(password):
+        password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
+        return password
+
+    @staticmethod
+    async def get_chat_headers(token):
+        return {
+            'Content-Type': 'application/json',
+            'Authorization': token
+        }
 
 
 
@@ -38,9 +75,14 @@
             'Content-Type': 'application/json',
             'Authorization': f"Bearer {token}"
         }
-        ans = await chat.chat_parameters(url, params, headers)
-        print(ans)
+        # ans = await chat.chat_parameters(url, params, headers)
+        # print(ans)
 
+        ping_url = "http://192.168.20.119:13002/console/api/workspaces"
+        user_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNzBhNWVhZWYtYzU4Yi00YTE0LTliOGQtYWE2MzY0ZmE1ZDE3IiwiZXhwIjoxNzM5MjU2MDMyLCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.tlxdRIVL2Ewgb0V4M5pj6v_U2yyvQxtCDrbvSxLjUBs"
+        token = "Bearer {}"
+        res = await chat.chat_ping(ping_url, {}, await chat.get_chat_headers(token.format(user_token)))
+        print(res)
 
     import asyncio
 

--
Gitblit v1.8.0