@waline/vercel 1.24.1 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config/config.js +2 -0
- package/src/controller/comment.js +1 -1
- package/src/extend/controller.js +1 -1
- package/src/service/notify.js +91 -12
package/package.json
CHANGED
package/src/config/config.js
CHANGED
|
@@ -38,6 +38,7 @@ const {
|
|
|
38
38
|
TG_TEMPLATE,
|
|
39
39
|
WX_TEMPLATE,
|
|
40
40
|
DISCORD_TEMPLATE,
|
|
41
|
+
LARK_TEMPLATE,
|
|
41
42
|
|
|
42
43
|
LEVELS,
|
|
43
44
|
} = process.env;
|
|
@@ -124,4 +125,5 @@ module.exports = {
|
|
|
124
125
|
TGTemplate: TG_TEMPLATE,
|
|
125
126
|
WXTemplate: WX_TEMPLATE,
|
|
126
127
|
DiscordTemplate: DISCORD_TEMPLATE,
|
|
128
|
+
LarkTemplate: LARK_TEMPLATE,
|
|
127
129
|
};
|
|
@@ -57,7 +57,7 @@ async function formatCmt(
|
|
|
57
57
|
}
|
|
58
58
|
comment.comment = markdownParser(comment.comment);
|
|
59
59
|
comment.like = Number(comment.like) || 0;
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// compat sql storage return number flag to string
|
|
62
62
|
if (typeof comment.sticky === 'string') {
|
|
63
63
|
comment.sticky = Boolean(Number(comment.sticky));
|
package/src/extend/controller.js
CHANGED
|
@@ -14,7 +14,7 @@ module.exports = {
|
|
|
14
14
|
},
|
|
15
15
|
locale(message, variables) {
|
|
16
16
|
const { lang } = this.get();
|
|
17
|
-
const locale = locales[(lang || '').toLowerCase()];
|
|
17
|
+
const locale = locales[(lang || 'zh-cn').toLowerCase()];
|
|
18
18
|
|
|
19
19
|
if (locale && locale[message]) {
|
|
20
20
|
message = locale[message];
|
package/src/service/notify.js
CHANGED
|
@@ -2,6 +2,7 @@ const FormData = require('form-data');
|
|
|
2
2
|
const nodemailer = require('nodemailer');
|
|
3
3
|
const fetch = require('node-fetch');
|
|
4
4
|
const nunjucks = require('nunjucks');
|
|
5
|
+
const crypto = require('crypto');
|
|
5
6
|
|
|
6
7
|
module.exports = class extends think.Service {
|
|
7
8
|
constructor(ctx) {
|
|
@@ -85,8 +86,8 @@ module.exports = class extends think.Service {
|
|
|
85
86
|
},
|
|
86
87
|
};
|
|
87
88
|
|
|
88
|
-
title =
|
|
89
|
-
content =
|
|
89
|
+
title = this.ctx.locale(title, data);
|
|
90
|
+
content = this.ctx.locale(content, data);
|
|
90
91
|
|
|
91
92
|
const form = new FormData();
|
|
92
93
|
|
|
@@ -134,8 +135,8 @@ module.exports = class extends think.Service {
|
|
|
134
135
|
【内容】:{{self.comment}}
|
|
135
136
|
<a href='{{site.postUrl}}'>查看详情</a>`;
|
|
136
137
|
|
|
137
|
-
title =
|
|
138
|
-
const desp =
|
|
138
|
+
title = this.ctx.locale(title, data);
|
|
139
|
+
const desp = this.ctx.locale(contentWechat, data);
|
|
139
140
|
|
|
140
141
|
content = desp.replace(/\n/g, '<br/>');
|
|
141
142
|
|
|
@@ -214,7 +215,7 @@ module.exports = class extends think.Service {
|
|
|
214
215
|
|
|
215
216
|
const form = new FormData();
|
|
216
217
|
|
|
217
|
-
form.append('msg',
|
|
218
|
+
form.append('msg', this.ctx.locale(contentQQ, data));
|
|
218
219
|
form.append('qq', QQ_ID);
|
|
219
220
|
|
|
220
221
|
return fetch(`https://qmsg.zendee.cn/send/${QMSG_KEY}`, {
|
|
@@ -283,7 +284,7 @@ module.exports = class extends think.Service {
|
|
|
283
284
|
|
|
284
285
|
const form = new FormData();
|
|
285
286
|
|
|
286
|
-
form.append('text',
|
|
287
|
+
form.append('text', this.ctx.locale(contentTG, data));
|
|
287
288
|
form.append('chat_id', TG_CHAT_ID);
|
|
288
289
|
form.append('parse_mode', 'MarkdownV2');
|
|
289
290
|
|
|
@@ -297,7 +298,7 @@ module.exports = class extends think.Service {
|
|
|
297
298
|
).then((resp) => resp.json());
|
|
298
299
|
|
|
299
300
|
if (!resp.ok) {
|
|
300
|
-
|
|
301
|
+
console.log('Telegram Notification Failed:' + JSON.stringify(resp));
|
|
301
302
|
}
|
|
302
303
|
}
|
|
303
304
|
|
|
@@ -327,8 +328,8 @@ module.exports = class extends think.Service {
|
|
|
327
328
|
},
|
|
328
329
|
};
|
|
329
330
|
|
|
330
|
-
title =
|
|
331
|
-
content =
|
|
331
|
+
title = this.ctx.locale(title, data);
|
|
332
|
+
content = this.ctx.locale(content, data);
|
|
332
333
|
|
|
333
334
|
const form = new FormData();
|
|
334
335
|
|
|
@@ -364,8 +365,8 @@ module.exports = class extends think.Service {
|
|
|
364
365
|
},
|
|
365
366
|
};
|
|
366
367
|
|
|
367
|
-
title =
|
|
368
|
-
content =
|
|
368
|
+
title = this.ctx.locale(title, data);
|
|
369
|
+
content = this.ctx.locale(
|
|
369
370
|
think.config('DiscordTemplate') ||
|
|
370
371
|
`💬 {{site.name|safe}} 有新评论啦
|
|
371
372
|
【评论者昵称】:{{self.nick}}
|
|
@@ -386,6 +387,83 @@ module.exports = class extends think.Service {
|
|
|
386
387
|
}).then((resp) => resp.json());
|
|
387
388
|
}
|
|
388
389
|
|
|
390
|
+
async lark({ title, content }, self, parent) {
|
|
391
|
+
const { LARK_WEBHOOK, LARK_SECRET, SITE_NAME, SITE_URL } = process.env;
|
|
392
|
+
|
|
393
|
+
if (!LARK_WEBHOOK) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
self.comment = self.comment.replace(/(<([^>]+)>)/gi, '');
|
|
398
|
+
|
|
399
|
+
const data = {
|
|
400
|
+
self,
|
|
401
|
+
parent,
|
|
402
|
+
site: {
|
|
403
|
+
name: SITE_NAME,
|
|
404
|
+
url: SITE_URL,
|
|
405
|
+
postUrl: SITE_URL + self.url + '#' + self.objectId,
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
content = nunjucks.renderString(
|
|
410
|
+
think.config('LarkTemplate') ||
|
|
411
|
+
`【网站名称】:{{site.name|safe}} \n【评论者昵称】:{{self.nick}}\n【评论者邮箱】:{{self.mail}}\n【内容】:{{self.comment}}【地址】:{{site.postUrl}}`,
|
|
412
|
+
data
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
const post = {
|
|
416
|
+
en_us: {
|
|
417
|
+
title: this.ctx.locale(title, data),
|
|
418
|
+
content: [
|
|
419
|
+
[
|
|
420
|
+
{
|
|
421
|
+
tag: 'text',
|
|
422
|
+
text: content,
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
],
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
let signData = {};
|
|
430
|
+
const msg = {
|
|
431
|
+
msg_type: 'post',
|
|
432
|
+
content: {
|
|
433
|
+
post,
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const sign = (timestamp, secret) => {
|
|
438
|
+
const signStr = timestamp + '\n' + secret;
|
|
439
|
+
|
|
440
|
+
return crypto.createHmac('sha256', signStr).update('').digest('base64');
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
if (LARK_SECRET) {
|
|
444
|
+
const timestamp = parseInt(+new Date() / 1000);
|
|
445
|
+
|
|
446
|
+
signData = { timestamp: timestamp, sign: sign(timestamp, LARK_SECRET) };
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const resp = await fetch(LARK_WEBHOOK, {
|
|
450
|
+
method: 'POST',
|
|
451
|
+
headers: {
|
|
452
|
+
'Content-Type': 'application/json',
|
|
453
|
+
},
|
|
454
|
+
body: JSON.stringify({
|
|
455
|
+
...signData,
|
|
456
|
+
...msg,
|
|
457
|
+
}),
|
|
458
|
+
}).then((resp) => resp.json());
|
|
459
|
+
|
|
460
|
+
if (resp.status !== 200) {
|
|
461
|
+
console.log('Lark Notification Failed:' + JSON.stringify(resp));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
console.log('FeiShu Notification Success:' + JSON.stringify(resp));
|
|
465
|
+
}
|
|
466
|
+
|
|
389
467
|
async run(comment, parent, disableAuthorNotify = false) {
|
|
390
468
|
const { AUTHOR_EMAIL, DISABLE_AUTHOR_NOTIFY } = process.env;
|
|
391
469
|
const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
|
|
@@ -416,9 +494,10 @@ module.exports = class extends think.Service {
|
|
|
416
494
|
const telegram = await this.telegram(comment, parent);
|
|
417
495
|
const pushplus = await this.pushplus({ title, content }, comment, parent);
|
|
418
496
|
const discord = await this.discord({ title, content }, comment, parent);
|
|
497
|
+
const lark = await this.lark({ title, content }, comment, parent);
|
|
419
498
|
|
|
420
499
|
if (
|
|
421
|
-
[wechat, qq, telegram, qywxAmWechat, pushplus, discord].every(
|
|
500
|
+
[wechat, qq, telegram, qywxAmWechat, pushplus, discord, lark].every(
|
|
422
501
|
think.isEmpty
|
|
423
502
|
) &&
|
|
424
503
|
!isReplyAuthor
|