@waline/vercel 1.23.2 → 1.23.4

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.23.2",
3
+ "version": "1.23.4",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -16,14 +16,14 @@
16
16
  "author": "lizheming <i@imnerd.org>",
17
17
  "dependencies": {
18
18
  "@cloudbase/node-sdk": "2.9.1",
19
- "@koa/cors": "3.4.1",
19
+ "@koa/cors": "3.4.2",
20
20
  "akismet": "2.0.7",
21
21
  "deta": "1.1.0",
22
22
  "dompurify": "2.4.0",
23
23
  "dy-node-ip2region": "1.0.1",
24
24
  "fast-csv": "4.3.6",
25
25
  "form-data": "4.0.0",
26
- "jsdom": "20.0.0",
26
+ "jsdom": "20.0.1",
27
27
  "jsonwebtoken": "8.5.1",
28
28
  "katex": "0.16.2",
29
29
  "leancloud-storage": "4.13.2",
@@ -32,8 +32,9 @@
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",
35
36
  "node-fetch": "2.6.7",
36
- "nodemailer": "6.7.8",
37
+ "nodemailer": "6.8.0",
37
38
  "nunjucks": "3.2.3",
38
39
  "phpass": "0.1.1",
39
40
  "prismjs": "1.29.0",
@@ -533,8 +533,8 @@ module.exports = class extends BaseRest {
533
533
  think.logger.debug(`Comment post frequence check OK!`);
534
534
 
535
535
  /** Akismet */
536
- const { COMMENT_AUDIT, AUTHOR_EMAIL, BLOGGER_EMAIL } = process.env;
537
- const AUTHOR = AUTHOR_EMAIL || BLOGGER_EMAIL;
536
+ const { COMMENT_AUDIT, AUTHOR_EMAIL } = process.env;
537
+ const AUTHOR = AUTHOR_EMAIL;
538
538
  const isAuthorComment = AUTHOR
539
539
  ? data.mail.toLowerCase() === AUTHOR.toLowerCase()
540
540
  : false;
@@ -623,7 +623,7 @@ module.exports = class extends BaseRest {
623
623
  : undefined;
624
624
 
625
625
  if (comment.status !== 'spam') {
626
- const notify = this.service('notify');
626
+ const notify = this.service('notify', this);
627
627
 
628
628
  await notify.run(
629
629
  { ...cmtReturn, mail: resp.mail, rawComment: comment },
@@ -715,7 +715,7 @@ module.exports = class extends BaseRest {
715
715
  pUser = pUser[0];
716
716
  }
717
717
 
718
- const notify = this.service('notify');
718
+ const notify = this.service('notify', this);
719
719
  const pcmtReturn = await formatCmt(
720
720
  pComment,
721
721
  pUser ? [pUser] : [],
@@ -28,7 +28,7 @@ module.exports = class extends BaseRest {
28
28
  return this.fail();
29
29
  }
30
30
 
31
- const notify = this.service('notify');
31
+ const notify = this.service('notify', this);
32
32
  const token = jwt.sign(user[0].email, this.config('jwtKey'));
33
33
  const profileUrl = `${this.ctx.serverURL}/ui/profile?token=${token}`;
34
34
 
@@ -77,7 +77,7 @@ module.exports = class extends BaseRest {
77
77
  }
78
78
 
79
79
  try {
80
- const notify = this.service('notify');
80
+ const notify = this.service('notify', this);
81
81
  const apiUrl =
82
82
  this.ctx.serverURL +
83
83
  '/verification?' +
@@ -11,5 +11,9 @@
11
11
  "Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!",
12
12
  "Duplicate Content": "Duplicate Content",
13
13
  "Comment too fast": "Comment too fast",
14
- "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}."
14
+ "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.",
15
+ "MAIL_SUBJECT": "Your comment on {{site.name | safe}} received a reply",
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;'> Your comment on <a style='text-decoration:none;color: #12ADDB;' href='{{site.url}}' target='_blank'>{{site.name}}</a> received a reply </h2>{{parent.nick}}, you wrote: <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> replied:</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'>View full reply</a> or visit <a style='text-decoration:none; color:#12addb' href='{{site.url}}' target='_blank'>{{site.name}}</a>.</p><br/> </div></div>",
17
+ "MAIL_SUBJECT_ADMIN": "New comment on {{site.name | safe}}",
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;'> New comment on <a style='text-decoration:none;color: #12ADDB;' href='{{site.url}}' target='_blank'>{{site.name}}</a> </h2> <p><strong>{{self.nick}}</strong> wrote:</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'>View page</a></p><br/></div>"
15
19
  }
@@ -11,5 +11,11 @@
11
11
  "Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "请尽快点击链接 <a href=\"{{url}}\">{{url}}</a> 登录并修改你的密码!",
12
12
  "Duplicate Content": "发送的内容之前已经发过",
13
13
  "Comment too fast": "评论太快啦,请慢点!",
14
- "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "注册确认邮件发送失败,请{%- if isAdmin -%}检查一下网站的邮件相关配置{% else %}确认你的邮箱输入无误并联系管理员{%- endif -%}。"
14
+ "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "注册确认邮件发送失败,请{%- if isAdmin -%}检查一下网站的邮件相关配置{% else %}确认你的邮箱输入无误并联系管理员{%- endif -%}。",
15
+ "MAIL_SUBJECT": "{{parent.nick | safe}},『{{site.name | safe}}』上的评论收到了回复",
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
+ "MAIL_SUBJECT_ADMIN": "{{site.name | safe}} 上有新评论了",
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>"
15
19
  }
20
+
21
+
@@ -11,5 +11,10 @@
11
11
  "Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "請盡快點擊鏈接 <a href=\"{{url}}\">{{url}}</a> 登錄並修改你的密碼!",
12
12
  "Duplicate Content": "發送的內容之前已經發過",
13
13
  "Comment too fast": "評論太快啦,請慢點!",
14
- "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "註冊確認郵件發送失敗,{%- if isAdmin -%}檢查一下網站的郵件相關配置{% else %}確認你的郵箱輸入無誤後聯繫管理員{%- endif -%}。"
14
+ "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "註冊確認郵件發送失敗,{%- if isAdmin -%}檢查一下網站的郵件相關配置{% else %}確認你的郵箱輸入無誤後聯繫管理員{%- endif -%}。",
15
+ "MAIL_SUBJECT": "{{parent.nick | safe}},『{{site.name | safe}}』上的評論收到回復",
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
+ "MAIL_SUBJECT_ADMIN": "{{site.name | safe}} 上有新評論了",
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
+
15
20
  }
@@ -21,7 +21,7 @@ module.exports = class extends Base {
21
21
  string: true,
22
22
  in: ['inc', 'desc'],
23
23
  default: 'inc',
24
- }
24
+ },
25
25
  };
26
26
  }
27
27
  };
@@ -4,9 +4,10 @@ const fetch = require('node-fetch');
4
4
  const nunjucks = require('nunjucks');
5
5
 
6
6
  module.exports = class extends think.Service {
7
- constructor(...args) {
8
- super(...args);
7
+ constructor(ctx) {
8
+ super(ctx);
9
9
 
10
+ this.ctx = ctx;
10
11
  const {
11
12
  SMTP_USER,
12
13
  SMTP_PASS,
@@ -26,7 +27,7 @@ module.exports = class extends think.Service {
26
27
  } else {
27
28
  config.host = SMTP_HOST;
28
29
  config.port = parseInt(SMTP_PORT);
29
- config.secure = SMTP_SECURE !== 'false';
30
+ config.secure = SMTP_SECURE && SMTP_SECURE !== 'false';
30
31
  }
31
32
  this.transporter = nodemailer.createTransport(config);
32
33
  }
@@ -53,8 +54,8 @@ module.exports = class extends think.Service {
53
54
  },
54
55
  };
55
56
 
56
- title = nunjucks.renderString(title, data);
57
- content = nunjucks.renderString(content, data);
57
+ title = this.ctx.locale(title, data);
58
+ content = this.ctx.locale(content, data);
58
59
 
59
60
  return this.transporter.sendMail({
60
61
  from:
@@ -379,10 +380,10 @@ module.exports = class extends think.Service {
379
380
  }
380
381
 
381
382
  async run(comment, parent, disableAuthorNotify = false) {
382
- const { AUTHOR_EMAIL, BLOGGER_EMAIL, DISABLE_AUTHOR_NOTIFY } = process.env;
383
+ const { AUTHOR_EMAIL, DISABLE_AUTHOR_NOTIFY } = process.env;
383
384
  const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
384
385
  think.config();
385
- const AUTHOR = AUTHOR_EMAIL || BLOGGER_EMAIL;
386
+ const AUTHOR = AUTHOR_EMAIL;
386
387
 
387
388
  const mailList = [];
388
389
  const isAuthorComment = AUTHOR
@@ -394,21 +395,8 @@ module.exports = class extends think.Service {
394
395
  const isCommentSelf =
395
396
  parent && parent.mail.toLowerCase() === comment.mail.toLowerCase();
396
397
 
397
- const title = mailSubjectAdmin || '{{site.name | safe}} 上有新评论了';
398
- const content =
399
- mailTemplateAdmin ||
400
- `
401
- <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;">
402
- <h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;">
403
- 您在<a style="text-decoration:none;color: #12ADDB;" href="{{site.url}}" target="_blank">{{site.name}}</a>上的文章有了新的评论
404
- </h2>
405
- <p><strong>{{self.nick}}</strong>回复说:</p>
406
- <div style="background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;">
407
- {{self.comment | safe}}
408
- </div>
409
- <p>您可以点击<a style="text-decoration:none; color:#12addb" href="{{site.postUrl}}" target="_blank">查看回复的完整內容</a></p>
410
- <br/>
411
- </div>`;
398
+ const title = mailSubjectAdmin || 'MAIL_SUBJECT_ADMIN';
399
+ const content = mailTemplateAdmin || 'MAIL_TEMPLATE_ADMIN';
412
400
 
413
401
  if (!DISABLE_AUTHOR_NOTIFY && !isAuthorComment && !disableAuthorNotify) {
414
402
  const wechat = await this.wechat({ title, content }, comment, parent);
@@ -445,25 +433,8 @@ module.exports = class extends think.Service {
445
433
  ) {
446
434
  mailList.push({
447
435
  to: parent.mail,
448
- title:
449
- mailSubject ||
450
- '{{parent.nick | safe}},『{{site.name | safe}}』上的评论收到了回复',
451
- content:
452
- mailTemplate ||
453
- `
454
- <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;">
455
- <h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;">
456
- 您在<a style="text-decoration:none;color: #12ADDB;" href="{{site.url}}" target="_blank">{{site.name}}</a>上的评论有了新的回复
457
- </h2>
458
- {{parent.nick}} 同学,您曾发表评论:
459
- <div style="padding:0 12px 0 12px;margin-top:18px">
460
- <div style="background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;">{{parent.comment | safe}}</div>
461
- <p><strong>{{self.nick}}</strong>回复说:</p>
462
- <div style="background-color: #f5f5f5;padding: 10px 15px;margin:18px 0;word-wrap:break-word;">{{self.comment | safe}}</div>
463
- <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>
464
- <br/>
465
- </div>
466
- </div>`,
436
+ title: mailSubject || 'MAIL_SUBJECT',
437
+ content: mailTemplate || 'MAIL_TEMPLATE',
467
438
  });
468
439
  }
469
440
 
@@ -47,7 +47,7 @@ module.exports = class extends Base {
47
47
  return (lastKey - Math.round(Math.random() * 100)).toString();
48
48
  }
49
49
 
50
- where(where) {
50
+ parseWhere(where) {
51
51
  if (think.isEmpty(where)) {
52
52
  return;
53
53
  }
@@ -122,6 +122,29 @@ module.exports = class extends Base {
122
122
  return this.complex(conditions, _isArrayKeys);
123
123
  }
124
124
 
125
+ where(where) {
126
+ const filter = this.parseWhere(where);
127
+
128
+ if (!where._complex) {
129
+ return filter;
130
+ }
131
+
132
+ const filters = [];
133
+
134
+ for (const k in where._complex) {
135
+ if (k === '_logic') {
136
+ continue;
137
+ }
138
+ filters.push({
139
+ ...this.parseWhere({ [k]: where._complex[k] }),
140
+ ...filter,
141
+ });
142
+ }
143
+
144
+ // just support OR logic for deta
145
+ return filters;
146
+ }
147
+
125
148
  async select(where, { limit, offset, field } = {}) {
126
149
  const conditions = this.where(where);
127
150
 
@@ -44,7 +44,7 @@ module.exports = class extends Base {
44
44
 
45
45
  instance.where(this.parseWhere(where));
46
46
  if (desc) {
47
- instance.order(`"${desc}" DESC`);
47
+ instance.order({ [desc]: 'DESC' });
48
48
  }
49
49
  if (limit || offset) {
50
50
  instance.limit(offset || 0, limit);
package/vanilla.js CHANGED
@@ -13,7 +13,7 @@ instance.run();
13
13
  let config = {};
14
14
 
15
15
  try {
16
- require('./config.js');
16
+ config = require('./config.js');
17
17
  } catch (e) {
18
18
  // do nothing
19
19
  }