mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 23:36:02 +00:00
feat: 改为同步
This commit is contained in:
@@ -2,7 +2,7 @@ import abc
|
||||
import uuid
|
||||
import json
|
||||
|
||||
import aiohttp
|
||||
import requests
|
||||
|
||||
|
||||
class APIGroup(metaclass=abc.ABCMeta):
|
||||
@@ -28,16 +28,15 @@ class APIGroup(metaclass=abc.ABCMeta):
|
||||
url = self.prefix + path
|
||||
data = json.dumps(data)
|
||||
headers['Content-Type'] = 'application/json'
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.request(
|
||||
method,
|
||||
url,
|
||||
data=data,
|
||||
params=params,
|
||||
headers=headers,
|
||||
**kwargs
|
||||
) as resp:
|
||||
return await resp.json()
|
||||
|
||||
return requests.request(
|
||||
method,
|
||||
url,
|
||||
data=data,
|
||||
params=params,
|
||||
headers=headers,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def gen_rid(
|
||||
self
|
||||
|
||||
@@ -9,7 +9,7 @@ class V2MainDataAPI(apigroup.APIGroup):
|
||||
def __init__(self, prefix: str):
|
||||
super().__init__(prefix+"/main")
|
||||
|
||||
async def post_update_record(
|
||||
def post_update_record(
|
||||
self,
|
||||
spent_seconds: int,
|
||||
infer_reason: str,
|
||||
@@ -17,7 +17,7 @@ class V2MainDataAPI(apigroup.APIGroup):
|
||||
new_version: str,
|
||||
):
|
||||
"""提交更新记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/update",
|
||||
data={
|
||||
@@ -31,12 +31,12 @@ class V2MainDataAPI(apigroup.APIGroup):
|
||||
}
|
||||
)
|
||||
|
||||
async def post_announcement_showed(
|
||||
def post_announcement_showed(
|
||||
self,
|
||||
ids: list[int],
|
||||
):
|
||||
"""提交公告已阅"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/announcement",
|
||||
data={
|
||||
|
||||
@@ -9,12 +9,12 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
||||
def __init__(self, prefix: str):
|
||||
super().__init__(prefix+"/plugin")
|
||||
|
||||
async def post_install_record(
|
||||
def post_install_record(
|
||||
self,
|
||||
plugin: dict
|
||||
):
|
||||
"""提交插件安装记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/install",
|
||||
data={
|
||||
@@ -23,12 +23,12 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
||||
}
|
||||
)
|
||||
|
||||
async def post_remove_record(
|
||||
def post_remove_record(
|
||||
self,
|
||||
plugin: dict
|
||||
):
|
||||
"""提交插件卸载记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/remove",
|
||||
data={
|
||||
@@ -37,14 +37,14 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
||||
}
|
||||
)
|
||||
|
||||
async def post_update_record(
|
||||
def post_update_record(
|
||||
self,
|
||||
plugin: dict,
|
||||
old_version: str,
|
||||
new_version: str,
|
||||
):
|
||||
"""提交插件更新记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/update",
|
||||
data={
|
||||
|
||||
@@ -9,7 +9,7 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
||||
def __init__(self, prefix: str):
|
||||
super().__init__(prefix+"/usage")
|
||||
|
||||
async def post_query_record(
|
||||
def post_query_record(
|
||||
self,
|
||||
session_type: str,
|
||||
session_id: str,
|
||||
@@ -20,7 +20,7 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
||||
retry_times: int,
|
||||
):
|
||||
"""提交请求记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/query",
|
||||
data={
|
||||
@@ -40,13 +40,13 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
||||
}
|
||||
)
|
||||
|
||||
async def post_event_record(
|
||||
def post_event_record(
|
||||
self,
|
||||
plugins: list[dict],
|
||||
event_name: str,
|
||||
):
|
||||
"""提交事件触发记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/event",
|
||||
data={
|
||||
@@ -59,14 +59,14 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
||||
}
|
||||
)
|
||||
|
||||
async def post_function_record(
|
||||
def post_function_record(
|
||||
self,
|
||||
plugin: dict,
|
||||
function_name: str,
|
||||
function_description: str,
|
||||
):
|
||||
"""提交内容函数使用记录"""
|
||||
return await self.do(
|
||||
return self.do(
|
||||
"POST",
|
||||
"/function",
|
||||
data={
|
||||
|
||||
@@ -109,7 +109,7 @@ def compare_version_str(v0: str, v1: str) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
async def update_all(cli: bool = False) -> bool:
|
||||
def update_all(cli: bool = False) -> bool:
|
||||
"""检查更新并下载源码"""
|
||||
start_time = time.time()
|
||||
|
||||
@@ -207,7 +207,7 @@ async def update_all(cli: bool = False) -> bool:
|
||||
with open("current_tag", "w") as f:
|
||||
f.write(current_tag)
|
||||
|
||||
await context.get_center_v2_api().main.post_update_record(
|
||||
context.get_center_v2_api().main.post_update_record(
|
||||
spent_seconds=int(time.time()-start_time),
|
||||
infer_reason="update",
|
||||
old_version=old_tag,
|
||||
|
||||
Reference in New Issue
Block a user