@waline/vercel 1.24.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -16,7 +16,7 @@
16
16
  "author": "lizheming <i@imnerd.org>",
17
17
  "dependencies": {
18
18
  "@cloudbase/node-sdk": "2.9.1",
19
- "@koa/cors": "3.4.2",
19
+ "@koa/cors": "4.0.0",
20
20
  "akismet": "2.0.7",
21
21
  "deta": "1.1.0",
22
22
  "dompurify": "2.4.0",
@@ -32,7 +32,6 @@
32
32
  "markdown-it-sub": "1.0.0",
33
33
  "markdown-it-sup": "1.0.0",
34
34
  "mathjax-full": "3.2.2",
35
- "mongodb": "4.10.0",
36
35
  "node-fetch": "2.6.7",
37
36
  "nodemailer": "6.8.0",
38
37
  "nunjucks": "3.2.3",
@@ -48,7 +47,7 @@
48
47
  "think-mongo": "2.2.1",
49
48
  "think-router-rest": "1.0.5",
50
49
  "thinkjs": "3.2.14",
51
- "ua-parser-js": "1.0.2"
50
+ "ua-parser-js": "1.0.32"
52
51
  },
53
52
  "engines": {
54
53
  "node": ">=14"
@@ -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
  };
@@ -58,6 +58,11 @@ async function formatCmt(
58
58
  comment.comment = markdownParser(comment.comment);
59
59
  comment.like = Number(comment.like) || 0;
60
60
 
61
+ // compat sql storage return number flag to string
62
+ if (typeof comment.sticky === 'string') {
63
+ comment.sticky = Boolean(Number(comment.sticky));
64
+ }
65
+
61
66
  return comment;
62
67
  }
63
68
 
@@ -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];
@@ -17,5 +17,3 @@
17
17
  "MAIL_SUBJECT_ADMIN": "{{site.name | safe}} 上有新评论了",
18
18
  "MAIL_TEMPLATE_ADMIN": "<div style='border-top:2px solid #12ADDB;box-shadow:0 1px 3px #AAAAAA;line-height:180%;padding:0 15px 12px;margin:50px auto;font-size:12px;'> <h2 style='border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;'> 您在<a style='text-decoration:none;color: #12ADDB;' href='{{site.url}}' target='_blank'>{{site.name}}</a>上的文章有了新的评论 </h2> <p><strong>{{self.nick}}</strong>回复说:</p><div style='background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;'>{{self.comment | safe}}</div><p>您可以点击<a style='text-decoration:none; color:#12addb' href='{{site.postUrl}}' target='_blank'>查看回复的完整內容</a></p><br/> </div>"
19
19
  }
20
-
21
-
@@ -16,5 +16,4 @@
16
16
  "MAIL_TEMPLATE": "<div style='border-top:2px solid #12ADDB;box-shadow:0 1px 3px #AAAAAA;line-height:180%;padding:0 15px 12px;margin:50px auto;font-size:12px;'> <h2 style='border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;'> 您在<a style='text-decoration:none;color: #12ADDB;' href='{{site.url}}' target='_blank'>{{site.name}}</a>上的品論有新的回復 </h2>{{parent.nick}}同學,您層發表評論: <div style='padding:0 12px 0 12px;margin-top:18px'> <div style='background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;'>{{parent.comment | safe}}</div><p><strong>{{self.nick}}</strong>回復說:</p><div style='background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;'>{{self.comment | safe}}</div><p>您可以點擊<a style='text-decoration:none; color:#12addb' href='{{site.postUrl}}' target='_blank'>查看回復的完整內容</a>,歡迎再次光臨<a style='text-decoration:none; color:#12addb' href='{{site.url}}' target='_blank'>{{site.name}}</a>。</p><br/> </div></div>",
17
17
  "MAIL_SUBJECT_ADMIN": "{{site.name | safe}} 上有新評論了",
18
18
  "MAIL_TEMPLATE_ADMIN": "<div style='border-top:2px solid #12ADDB;box-shadow:0 1px 3px #AAAAAA;line-height:180%;padding:0 15px 12px;margin:50px auto;font-size:12px;'> <h2 style='border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;'> 您在<a style='text-decoration:none;color: #12ADDB;' href='{{site.url}}' target='_blank'>{{site.name}}</a>上的文章有新評論了 </h2> <p><strong>{{self.nick}}</strong>回復說:</p><div style='background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;'>{{self.comment | safe}}</div><p>您可以點擊<a style='text-decoration:none; color:#12addb' href='{{site.postUrl}}' target='_blank'>查看回復的完整內容</a></p><br/> </div>"
19
-
20
19
  }
@@ -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 = nunjucks.renderString(title, data);
89
- content = nunjucks.renderString(content, data);
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 = nunjucks.renderString(title, data);
138
- const desp = nunjucks.renderString(contentWechat, data);
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', nunjucks.renderString(contentQQ, data));
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,15 +284,22 @@ module.exports = class extends think.Service {
283
284
 
284
285
  const form = new FormData();
285
286
 
286
- form.append('text', nunjucks.renderString(contentTG, data));
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
 
290
- return fetch(`https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`, {
291
- method: 'POST',
292
- header: form.getHeaders(),
293
- body: form,
294
- }).then((resp) => resp.json());
291
+ const resp = await fetch(
292
+ `https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`,
293
+ {
294
+ method: 'POST',
295
+ header: form.getHeaders(),
296
+ body: form,
297
+ }
298
+ ).then((resp) => resp.json());
299
+
300
+ if (!resp.ok) {
301
+ console.log('Telegram Notification Failed:' + JSON.stringify(resp));
302
+ }
295
303
  }
296
304
 
297
305
  async pushplus({ title, content }, self, parent) {
@@ -320,8 +328,8 @@ module.exports = class extends think.Service {
320
328
  },
321
329
  };
322
330
 
323
- title = nunjucks.renderString(title, data);
324
- content = nunjucks.renderString(content, data);
331
+ title = this.ctx.locale(title, data);
332
+ content = this.ctx.locale(content, data);
325
333
 
326
334
  const form = new FormData();
327
335
 
@@ -357,8 +365,8 @@ module.exports = class extends think.Service {
357
365
  },
358
366
  };
359
367
 
360
- title = nunjucks.renderString(title, data);
361
- content = nunjucks.renderString(
368
+ title = this.ctx.locale(title, data);
369
+ content = this.ctx.locale(
362
370
  think.config('DiscordTemplate') ||
363
371
  `💬 {{site.name|safe}} 有新评论啦
364
372
  【评论者昵称】:{{self.nick}}
@@ -379,6 +387,83 @@ module.exports = class extends think.Service {
379
387
  }).then((resp) => resp.json());
380
388
  }
381
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
+
382
467
  async run(comment, parent, disableAuthorNotify = false) {
383
468
  const { AUTHOR_EMAIL, DISABLE_AUTHOR_NOTIFY } = process.env;
384
469
  const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
@@ -409,9 +494,10 @@ module.exports = class extends think.Service {
409
494
  const telegram = await this.telegram(comment, parent);
410
495
  const pushplus = await this.pushplus({ title, content }, comment, parent);
411
496
  const discord = await this.discord({ title, content }, comment, parent);
497
+ const lark = await this.lark({ title, content }, comment, parent);
412
498
 
413
499
  if (
414
- [wechat, qq, telegram, qywxAmWechat, pushplus, discord].every(
500
+ [wechat, qq, telegram, qywxAmWechat, pushplus, discord, lark].every(
415
501
  think.isEmpty
416
502
  ) &&
417
503
  !isReplyAuthor
@@ -1,4 +1,4 @@
1
- const { ObjectId } = require('mongodb');
1
+ const { ObjectID: ObjectId } = require('think-mongo/lib/model');
2
2
  const Base = require('./base');
3
3
 
4
4
  module.exports = class extends Base {