feat: v0.1.7 消息推送模块 - 多通道通知(飞书/Server酱/Bark/Telegram/Webhook)+ 转存/清理/Cookie推送事件 + 推送配置页面

This commit is contained in:
root
2026-05-15 23:59:55 +08:00
parent 1c7b750cda
commit e38adee8ff
9 changed files with 359 additions and 59 deletions

View File

@@ -6,6 +6,7 @@ import { QuarkDriver } from './drivers/quark.driver';
import { BaiduDriver } from './drivers/baidu.driver';
import { CloudConfig, getAndValidateCredential, getActiveCloudConfigs } from './credential.service';
import { lookupIpLocation } from './ip-lookup';
import { notify, notifyError, notifyInfo, notifyWarn, notifyEvent } from './notification.service';
/** In-flight save dedup: prevents concurrent saves of the same URL (race condition fix) */
const inFlightSaves = new Map<string, Promise<SaveResult>>();
@@ -193,15 +194,29 @@ async function doSaveFromShare(shareUrl: string, cloudType: string, sourceTitle?
const durationMs = Date.now() - startTime;
if (driverResult.success) {
const nickname = config.nickname || cloudType;
notifyEvent('save_success', `✅ 转存成功`,
`**${cloudType}** · ${nickname}\n文件: ${driverResult.folderName || sourceTitle || shareUrl}\n耗时: ${((Date.now() - startTime) / 1000).toFixed(1)}s`,
'info');
db.prepare(
`UPDATE cloud_configs SET last_used_at = datetime('now','localtime'), total_saves = total_saves + 1, consecutive_failures = 0 WHERE id = ?`
).run(config.id);
} else if ((driverResult as any).cookieExpired) {
// Cookie expired — don't count as failure, user needs to re-login
notifyEvent('cookie_expire', `⚠️ Cookie过期`,
`**${cloudType}** · ${config.nickname || '未知'}\n链接: ${shareUrl}\n请重新登录`,
'error');
} else {
db.prepare(
`UPDATE cloud_configs SET consecutive_failures = consecutive_failures + 1 WHERE id = ?`
).run(config.id);
const failCount = (db.prepare(`SELECT consecutive_failures FROM cloud_configs WHERE id = ?`).get(config.id) as any)?.consecutive_failures || 0;
if (failCount >= 3) {
notifyEvent('save_fail', `❌ 转存连续失败 ${failCount}`,
`**${cloudType}** · ${config.nickname || '未知'}\n链接: ${shareUrl}\n错误: ${driverResult.message}`,
'warn');
}
}
db.prepare(