fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -220,7 +220,10 @@ class PluginManager:
return None
def list_plugins(
self, project_id: str = None, plugin_type: str = None, status: str = None,
self,
project_id: str | None = None,
plugin_type: str = None,
status: str = None,
) -> list[Plugin]:
"""列出插件"""
conn = self.db.get_conn()
@@ -241,7 +244,8 @@ class PluginManager:
where_clause = " AND ".join(conditions) if conditions else "1 = 1"
rows = conn.execute(
f"SELECT * FROM plugins WHERE {where_clause} ORDER BY created_at DESC", params,
f"SELECT * FROM plugins WHERE {where_clause} ORDER BY created_at DESC",
params,
).fetchall()
conn.close()
@@ -310,7 +314,11 @@ class PluginManager:
# ==================== Plugin Config ====================
def set_plugin_config(
self, plugin_id: str, key: str, value: str, is_encrypted: bool = False,
self,
plugin_id: str,
key: str,
value: str,
is_encrypted: bool = False,
) -> PluginConfig:
"""设置插件配置"""
conn = self.db.get_conn()
@@ -367,7 +375,8 @@ class PluginManager:
"""获取插件所有配置"""
conn = self.db.get_conn()
rows = conn.execute(
"SELECT config_key, config_value FROM plugin_configs WHERE plugin_id = ?", (plugin_id,),
"SELECT config_key, config_value FROM plugin_configs WHERE plugin_id = ?",
(plugin_id,),
).fetchall()
conn.close()
@@ -377,7 +386,8 @@ class PluginManager:
"""删除插件配置"""
conn = self.db.get_conn()
cursor = conn.execute(
"DELETE FROM plugin_configs WHERE plugin_id = ? AND config_key = ?", (plugin_id, key),
"DELETE FROM plugin_configs WHERE plugin_id = ? AND config_key = ?",
(plugin_id, key),
)
conn.commit()
conn.close()
@@ -408,10 +418,10 @@ class ChromeExtensionHandler:
def create_token(
self,
name: str,
user_id: str = None,
project_id: str = None,
user_id: str | None = None,
project_id: str | None = None,
permissions: list[str] = None,
expires_days: int = None,
expires_days: int | None = None,
) -> ChromeExtensionToken:
"""创建 Chrome 扩展令牌"""
token_id = str(uuid.uuid4())[:UUID_LENGTH]
@@ -512,7 +522,8 @@ class ChromeExtensionHandler:
"""撤销令牌"""
conn = self.pm.db.get_conn()
cursor = conn.execute(
"UPDATE chrome_extension_tokens SET is_revoked = 1 WHERE id = ?", (token_id,),
"UPDATE chrome_extension_tokens SET is_revoked = 1 WHERE id = ?",
(token_id,),
)
conn.commit()
conn.close()
@@ -520,7 +531,9 @@ class ChromeExtensionHandler:
return cursor.rowcount > 0
def list_tokens(
self, user_id: str = None, project_id: str = None,
self,
user_id: str | None = None,
project_id: str = None,
) -> list[ChromeExtensionToken]:
"""列出令牌"""
conn = self.pm.db.get_conn()
@@ -569,7 +582,7 @@ class ChromeExtensionHandler:
url: str,
title: str,
content: str,
html_content: str = None,
html_content: str | None = None,
) -> dict:
"""导入网页内容"""
if not token.project_id:
@@ -616,7 +629,7 @@ class BotHandler:
self,
session_id: str,
session_name: str,
project_id: str = None,
project_id: str | None = None,
webhook_url: str = "",
secret: str = "",
) -> BotSession:
@@ -674,7 +687,7 @@ class BotHandler:
return self._row_to_session(row)
return None
def list_sessions(self, project_id: str = None) -> list[BotSession]:
def list_sessions(self, project_id: str | None = None) -> list[BotSession]:
"""列出会话"""
conn = self.pm.db.get_conn()
@@ -849,7 +862,7 @@ class BotHandler:
}
except Exception as e:
return {"success": False, "error": f"Failed to process audio: {str(e)}"}
return {"success": False, "error": f"Failed to process audio: {e!s}"}
async def _handle_file_message(self, session: BotSession, message: dict) -> dict:
"""处理文件消息"""
@@ -897,12 +910,17 @@ class BotHandler:
async with httpx.AsyncClient() as client:
response = await client.post(
session.webhook_url, json=payload, headers={"Content-Type": "application/json"},
session.webhook_url,
json=payload,
headers={"Content-Type": "application/json"},
)
return response.status_code == 200
async def _send_dingtalk_message(
self, session: BotSession, message: str, msg_type: str,
self,
session: BotSession,
message: str,
msg_type: str,
) -> bool:
"""发送钉钉消息"""
timestamp = str(round(time.time() * 1000))
@@ -928,7 +946,9 @@ class BotHandler:
async with httpx.AsyncClient() as client:
response = await client.post(
url, json=payload, headers={"Content-Type": "application/json"},
url,
json=payload,
headers={"Content-Type": "application/json"},
)
return response.status_code == 200
@@ -944,9 +964,9 @@ class WebhookIntegration:
self,
name: str,
endpoint_url: str,
project_id: str = None,
project_id: str | None = None,
auth_type: str = "none",
auth_config: dict = None,
auth_config: dict | None = None,
trigger_events: list[str] = None,
) -> WebhookEndpoint:
"""创建 Webhook 端点"""
@@ -1004,7 +1024,7 @@ class WebhookIntegration:
return self._row_to_endpoint(row)
return None
def list_endpoints(self, project_id: str = None) -> list[WebhookEndpoint]:
def list_endpoints(self, project_id: str | None = None) -> list[WebhookEndpoint]:
"""列出端点"""
conn = self.pm.db.get_conn()
@@ -1115,7 +1135,10 @@ class WebhookIntegration:
async with httpx.AsyncClient() as client:
response = await client.post(
endpoint.endpoint_url, json=payload, headers=headers, timeout=30.0,
endpoint.endpoint_url,
json=payload,
headers=headers,
timeout=30.0,
)
success = response.status_code in [200, 201, 202]
@@ -1229,7 +1252,7 @@ class WebDAVSyncManager:
return self._row_to_sync(row)
return None
def list_syncs(self, project_id: str = None) -> list[WebDAVSync]:
def list_syncs(self, project_id: str | None = None) -> list[WebDAVSync]:
"""列出同步配置"""
conn = self.pm.db.get_conn()