优化IO问题
This commit is contained in:
@@ -56,7 +56,8 @@ class QL:
|
||||
url = f"{self.address}/open/envs?searchValue="
|
||||
headers = {"Authorization": self.auth}
|
||||
try:
|
||||
async with aiohttp.ClientSession().get(url, headers=headers, timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
async with aiohttp.ClientSession().get(url, headers=headers,
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
if response.status == 200:
|
||||
rjson = await response.json()
|
||||
if rjson['code'] == 200:
|
||||
@@ -81,7 +82,7 @@ class QL:
|
||||
headers = {"Authorization": self.auth, "content-type": "application/json"}
|
||||
try:
|
||||
async with aiohttp.ClientSession().delete(url, headers=headers, json=ids,
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
if response.status == 200:
|
||||
rjson = await response.json()
|
||||
if rjson['code'] == 200:
|
||||
@@ -106,7 +107,7 @@ class QL:
|
||||
headers = {"Authorization": self.auth, "content-type": "application/json"}
|
||||
try:
|
||||
async with aiohttp.ClientSession().post(url, headers=headers, json=envs,
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
if response.status == 200:
|
||||
rjson = await response.json()
|
||||
if rjson['code'] == 200:
|
||||
@@ -130,7 +131,8 @@ class QL:
|
||||
url = f"{self.address}/open/envs"
|
||||
headers = {"Authorization": self.auth, "content-type": "application/json"}
|
||||
try:
|
||||
async with aiohttp.ClientSession().put(url, headers=headers, json=env, timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
async with aiohttp.ClientSession().put(url, headers=headers, json=env,
|
||||
timeout=aiohttp.ClientTimeout(total=15)) as response:
|
||||
if response.status == 200:
|
||||
rjson = await response.json()
|
||||
if rjson['code'] == 200:
|
||||
@@ -279,7 +281,7 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"处理后的token格式: {token}")
|
||||
try:
|
||||
# 设置京东Token
|
||||
result = self.set_jd_token(token, remark)
|
||||
result = await self.set_jd_token(token, remark)
|
||||
await bot.send_text_message((roomid if roomid else sender), result, sender)
|
||||
return True, "处理成功"
|
||||
|
||||
@@ -288,13 +290,13 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
await bot.send_text_message((roomid if roomid else sender), f"❌处理出错: {str(e)}", sender)
|
||||
return False, f"处理出错: {e}"
|
||||
|
||||
def set_jd_token(self, token: str, remark: str) -> str:
|
||||
async def set_jd_token(self, token: str, remark: str) -> str:
|
||||
"""设置京东Token"""
|
||||
if not self.ql.valid:
|
||||
return f"❌ 青龙面板连接失败,请检查配置"
|
||||
|
||||
# 检查是否已存在相同备注的环境变量
|
||||
envs = self.ql.getEnvs()
|
||||
envs = await self.ql.getEnvs()
|
||||
if not envs:
|
||||
return f"❌ 获取环境变量失败"
|
||||
|
||||
@@ -324,10 +326,10 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
# 更新已存在的环境变量,保留原有的备注或使用新的备注
|
||||
existing_remarks = existing_env.get('remarks', '')
|
||||
final_remarks = remark if remark else existing_remarks
|
||||
|
||||
|
||||
existing_env['value'] = token
|
||||
env_update: dict = {"id": env_id, "value": token, "remarks": final_remarks, "name": "JD_COOKIE"}
|
||||
result = self.ql.updateEnv(env_update)
|
||||
result = await self.ql.updateEnv(env_update)
|
||||
if result:
|
||||
return f"✅ 已成功更新京东账号 [{final_remarks}] 的Token (pt_pin: {current_pt_pin})"
|
||||
else:
|
||||
@@ -335,7 +337,7 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
else:
|
||||
# 添加新的环境变量
|
||||
new_env = [{"name": "JD_COOKIE", "value": token, "remarks": remark}]
|
||||
result = self.ql.addEnvs(new_env)
|
||||
result = await self.ql.addEnvs(new_env)
|
||||
if result:
|
||||
return f"✅ 已成功添加京东账号 [{remark}] 的Token (pt_pin: {current_pt_pin})"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user