Skip to content

Commit d2d76b0

Browse files
author
Taois
committed
feat: 增加邮箱推送,增加qjs性能测试
1 parent d21af0b commit d2d76b0

File tree

5 files changed

+108
-7
lines changed

5 files changed

+108
-7
lines changed

.env.development

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ LIVE_URL = 'https://livetv.wqwqwq.sbs/tv.m3u'
2525
MAX_TASK = 8
2626
dingding_webhook=
2727
wechat_webhook=
28-
tx_news_guonei_api_key=
28+
tx_news_guonei_api_key=
29+
30+
# QQ邮箱配置
31+
QQ_EMAIL =
32+
QQ_SMTP_AUTH_CODE =

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drpy-node",
3-
"version": "1.2.10",
3+
"version": "1.2.11",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
@@ -46,6 +46,7 @@
4646
"minizlib": "^3.0.1",
4747
"node-forge": "^1.3.1",
4848
"node-sqlite3-wasm": "^0.8.35",
49+
"nodemailer": "^7.0.5",
4950
"p-queue": "^8.0.1",
5051
"pino": "^9.7.0",
5152
"pinyin": "^4.0.0",

scripts/cron/qqemail_test.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import MessageSender from '../../utils/message_sender.js';
2+
3+
export default {
4+
schedule: {
5+
//cron: '0 */30 * * * *',
6+
timezone: 'Asia/Shanghai', // 直接用北京时间时区
7+
runOnInit: false // 启动时立即执行一次
8+
},
9+
run: async (fastify) => {
10+
fastify.log.info('📊 版本监测...');
11+
let vercode = "V1.0";
12+
let config = {
13+
//to: '[email protected],[email protected]', 不填默认发给自己
14+
subject: '版本监听',
15+
text: `有更新,版本${vercode}`,
16+
html: `<div style="font-family:Arial,sans-serif;max-width:600px;margin:0 auto;padding:20px;background:#f8f9fa;border-radius:8px;">
17+
<p style="font-size:16px;color:#333;margin:0 0 15px 0;"><span style="color:#4CAF50;font-weight:bold;">🔄 更新通知:</span>当前版本 <strong style="color:#2196F3;">${vercode}</strong> 已发布</p></div>`
18+
};
19+
await MessageSender.send(config,2);
20+
fastify.log.info('📤 send qqemail message successfully');
21+
}
22+
};

spider/catvod/猫测试.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ function init(ext) {
1212
console.log('init');
1313
}
1414

15-
function home(filter) {
15+
function qjs_test() {
1616
console.log('typeof getProxyUrl:', typeof getProxyUrl);
1717
if (typeof getProxyUrl === 'function') {
1818
console.log('getProxyUrl():', getProxyUrl());
1919
}
20+
const t1 = Date.now()
21+
let str = '';
22+
for (let i = 0; i < 1000_000; i++) {
23+
str += 'a';
24+
}
25+
const t2 = Date.now()
26+
console.log(`qjs字符串拼接测试耗时: ${Math.ceil(t2 - t1)} ms`);
27+
}
28+
29+
function home(filter) {
30+
qjs_test();
2031
let classes = [];
2132
classes.push({
2233
'type_id': 'test',

utils/message_sender.js

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import axios from 'axios';
2+
import nodemailer from 'nodemailer';
23

34
export default class MessageSender {
45
static TYPE = {
56
DINGDING: 0,
67
WECHAT: 1,
8+
QQEMAIL: 2,
79
// 未来可扩展更多类型...
810
};
911

1012
/**
1113
* 发送消息
12-
* @param {string} text 消息文本
13-
* @param {number} type 消息类型(0: 钉钉,1: 企业微信),默认 0
14+
* @param {string|object} text 消息文本(字符串或邮件配置对象)
15+
* @param {number} type 消息类型(0: 钉钉,1: 企业微信,2: QQ邮箱),默认 0
1416
*/
1517
static async send(text, type = MessageSender.TYPE.DINGDING) {
16-
if (!text || typeof text !== 'string') {
17-
console.warn('[MessageSender] 消息内容必须是字符串');
18+
if (!text) {
19+
console.warn('[MessageSender] 消息内容不能为空');
20+
return;
21+
}
22+
23+
// QQ邮箱只允许对象,其他类型必须为字符串
24+
if (type === MessageSender.TYPE.QQEMAIL && typeof text !== 'object') {
25+
console.warn('[MessageSender] QQ邮箱类型只支持配置对象');
26+
return;
27+
}
28+
29+
if (type !== MessageSender.TYPE.QQEMAIL && typeof text !== 'string') {
30+
console.warn('[MessageSender] 非邮箱类型消息内容必须是字符串');
1831
return;
1932
}
2033

@@ -27,6 +40,10 @@ export default class MessageSender {
2740
await this.#sendWeChat(text);
2841
break;
2942

43+
case MessageSender.TYPE.QQEMAIL:
44+
await this.#sendQQEmail(text);
45+
break;
46+
3047
default:
3148
console.warn(`[MessageSender] 不支持的消息类型: ${type}`);
3249
}
@@ -65,4 +82,50 @@ export default class MessageSender {
6582
console.error('[MessageSender] 企业微信消息发送失败:', err.message);
6683
}
6784
}
85+
86+
/**
87+
* 发送QQ邮件(支持文本/HTML/多收件人)
88+
* @param {object} config 邮件配置对象
89+
* @property {string} [to] 收件人邮箱,默认使用环境变量QQ_EMAIL
90+
* @property {string} [subject] 邮件主题,默认"系统通知"
91+
* @property {string} [text] 纯文本内容
92+
* @property {string} [html] HTML内容
93+
* @property {Array} [attachments] 邮件附件
94+
*/
95+
static async #sendQQEmail(config) {
96+
const {QQ_EMAIL, QQ_SMTP_AUTH_CODE} = process.env;
97+
98+
if (!QQ_EMAIL || !QQ_SMTP_AUTH_CODE) {
99+
console.log('[MessageSender] 未配置QQ邮箱或SMTP授权码,跳过邮件发送');
100+
return;
101+
}
102+
103+
// 创建带连接池的邮件传输器
104+
const transporter = nodemailer.createTransport({
105+
//pool: true, // 启用连接池
106+
host: 'smtp.qq.com',
107+
port: 465,
108+
secure: true,
109+
auth: {
110+
user: QQ_EMAIL,
111+
pass: QQ_SMTP_AUTH_CODE
112+
}
113+
});
114+
115+
try {
116+
// 构建邮件选项,保护关键字段并提供默认值
117+
const mailOptions = {
118+
from: `"系统通知" <${QQ_EMAIL}>`, // 固定发件人
119+
to: config.to || QQ_EMAIL, // 允许自定义收件人
120+
...config
121+
};
122+
123+
const info = await transporter.sendMail(mailOptions);
124+
console.log('[MessageSender] QQ邮件已发送: %s', info.accepted);
125+
} catch (err) {
126+
console.error('[MessageSender] QQ邮件发送失败:', err.message);
127+
} finally {
128+
transporter.close(); // 关闭连接池
129+
}
130+
}
68131
}

0 commit comments

Comments
 (0)