修复通知渠道

This commit is contained in:
zhinianboke 2025-08-22 12:31:05 +08:00
parent 2432f01a5d
commit 62f38afce0
2 changed files with 28 additions and 8 deletions

View File

@ -354,7 +354,7 @@ class DBManager:
CREATE TABLE IF NOT EXISTS notification_channels ( CREATE TABLE IF NOT EXISTS notification_channels (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('qq')), type TEXT NOT NULL CHECK (type IN ('qq','ding_talk','dingtalk','feishu','lark','bark','email','webhook','wechat','telegram')),
config TEXT NOT NULL, config TEXT NOT NULL,
enabled BOOLEAN DEFAULT TRUE, enabled BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@ -566,6 +566,14 @@ class DBManager:
self.upgrade_keywords_table_for_image_support(cursor) self.upgrade_keywords_table_for_image_support(cursor)
self.set_system_setting("db_version", "1.3", "数据库版本号") self.set_system_setting("db_version", "1.3", "数据库版本号")
logger.info("数据库升级到版本1.3完成") logger.info("数据库升级到版本1.3完成")
# 升级到版本1.4 - 添加关键词类型和图片URL字段
if current_version < "1.4":
logger.info("开始升级数据库到版本1.4...")
self.upgrade_notification_channels_types(cursor)
self.set_system_setting("db_version", "1.4", "数据库版本号")
logger.info("数据库升级到版本1.4完成")
# 迁移遗留数据(在所有版本升级完成后执行) # 迁移遗留数据(在所有版本升级完成后执行)
self.migrate_legacy_data(cursor) self.migrate_legacy_data(cursor)
@ -802,13 +810,13 @@ class DBManager:
existing_data = cursor.fetchall() existing_data = cursor.fetchall()
logger.info(f"备份 {count} 条通知渠道数据") logger.info(f"备份 {count} 条通知渠道数据")
# 创建新表,支持更多渠道类型 # 创建新表,支持所有通知渠道类型
cursor.execute(''' cursor.execute('''
CREATE TABLE notification_channels_new ( CREATE TABLE notification_channels_new (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
type TEXT NOT NULL CHECK (type IN ('qq','ding_talk','dingtalk','email','webhook','wechat','telegram')), type TEXT NOT NULL CHECK (type IN ('qq','ding_talk','dingtalk','feishu','lark','bark','email','webhook','wechat','telegram')),
config TEXT NOT NULL, config TEXT NOT NULL,
enabled BOOLEAN DEFAULT TRUE, enabled BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@ -823,15 +831,18 @@ class DBManager:
# 处理类型映射,支持更多渠道类型 # 处理类型映射,支持更多渠道类型
old_type = row[3] if len(row) > 3 else 'qq' # type字段 old_type = row[3] if len(row) > 3 else 'qq' # type字段
# 扩展的类型映射规则 # 完整的类型映射规则,支持所有通知渠道
type_mapping = { type_mapping = {
'ding_talk': 'dingtalk', # 统一为dingtalk 'ding_talk': 'dingtalk', # 统一为dingtalk
'dingtalk': 'dingtalk', 'dingtalk': 'dingtalk',
'qq': 'qq', 'qq': 'qq',
'email': 'email', # 现在支持email 'feishu': 'feishu', # 飞书通知
'webhook': 'webhook', # 现在支持webhook 'lark': 'lark', # 飞书通知(英文名)
'wechat': 'wechat', # 现在支持wechat 'bark': 'bark', # Bark通知
'telegram': 'telegram' # 现在支持telegram 'email': 'email', # 邮件通知
'webhook': 'webhook', # Webhook通知
'wechat': 'wechat', # 微信通知
'telegram': 'telegram' # Telegram通知
} }
new_type = type_mapping.get(old_type, 'qq') # 默认为qq new_type = type_mapping.get(old_type, 'qq') # 默认为qq
@ -862,6 +873,15 @@ class DBManager:
cursor.execute("ALTER TABLE notification_channels_new RENAME TO notification_channels") cursor.execute("ALTER TABLE notification_channels_new RENAME TO notification_channels")
logger.info("notification_channels表类型升级完成") logger.info("notification_channels表类型升级完成")
logger.info("✅ 现在支持以下所有通知渠道类型:")
logger.info(" - qq (QQ通知)")
logger.info(" - ding_talk/dingtalk (钉钉通知)")
logger.info(" - feishu/lark (飞书通知)")
logger.info(" - bark (Bark通知)")
logger.info(" - email (邮件通知)")
logger.info(" - webhook (Webhook通知)")
logger.info(" - wechat (微信通知)")
logger.info(" - telegram (Telegram通知)")
return True return True
except Exception as e: except Exception as e:
logger.error(f"升级notification_channels表类型失败: {e}") logger.error(f"升级notification_channels表类型失败: {e}")

BIN
static/wechat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB