@waline/vercel 1.9.0 → 1.11.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.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "repository": "https://github.com/walinejs/waline",
6
6
  "license": "MIT",
@@ -36,6 +36,7 @@ const {
36
36
  QQ_TEMPLATE,
37
37
  TG_TEMPLATE,
38
38
  WX_TEMPLATE,
39
+ DISCORD_TEMPLATE,
39
40
  } = process.env;
40
41
 
41
42
  let storage = 'leancloud';
@@ -113,4 +114,5 @@ module.exports = {
113
114
  QQTemplate: QQ_TEMPLATE,
114
115
  TGTemplate: TG_TEMPLATE,
115
116
  WXTemplate: WX_TEMPLATE,
117
+ DiscordTemplate: DISCORD_TEMPLATE,
116
118
  };
@@ -78,7 +78,7 @@ module.exports = class extends BaseRest {
78
78
  }
79
79
 
80
80
  async putAction() {
81
- const { display_name, url, password } = this.post();
81
+ const { display_name, url, avatar, password } = this.post();
82
82
  const { objectId } = this.ctx.state.userInfo;
83
83
 
84
84
  const updateData = {};
@@ -91,6 +91,10 @@ module.exports = class extends BaseRest {
91
91
  updateData.url = url;
92
92
  }
93
93
 
94
+ if (avatar) {
95
+ updateData.avatar = avatar;
96
+ }
97
+
94
98
  if (password) {
95
99
  updateData.password = new PasswordHash().hashPassword(password);
96
100
  }
@@ -13,7 +13,10 @@ module.exports = function () {
13
13
  window.SITE_URL = ${JSON.stringify(process.env.SITE_URL)};
14
14
  window.SITE_NAME = ${JSON.stringify(process.env.SITE_NAME)};
15
15
  </script>
16
- <script src="https://cdn.jsdelivr.net/npm/@waline/admin"></script>
16
+ <script src="${
17
+ process.env.WALINE_ADMIN_MODULE_ASSET_URL ||
18
+ 'https://cdn.jsdelivr.net/npm/@waline/admin'
19
+ }"></script>
17
20
  </body>
18
21
  </html>`;
19
22
  };
@@ -317,6 +317,42 @@ module.exports = class extends think.Service {
317
317
  });
318
318
  }
319
319
 
320
+ async discord({ title, content }, self, parent) {
321
+ const { DISCORD_WEBHOOK, SITE_NAME, SITE_URL } = process.env;
322
+ if (!DISCORD_WEBHOOK) {
323
+ return false;
324
+ }
325
+
326
+ const data = {
327
+ self,
328
+ parent,
329
+ site: {
330
+ name: SITE_NAME,
331
+ url: SITE_URL,
332
+ postUrl: SITE_URL + self.url + '#' + self.objectId,
333
+ },
334
+ };
335
+ title = nunjucks.renderString(title, data);
336
+ content = nunjucks.renderString(
337
+ think.config('DiscordTemplate') ||
338
+ `💬 {{site.name|safe}}的文章《{{postName}}》有新评论啦
339
+ 【评论者昵称】:{{self.nick}}
340
+ 【评论者邮箱】:{{self.mail}}
341
+ 【内容】:{{self.comment}}
342
+ 【地址】:{{site.postUrl}}`,
343
+ data
344
+ );
345
+
346
+ return request({
347
+ uri: DISCORD_WEBHOOK,
348
+ method: 'POST',
349
+ form: {
350
+ content: title + '\n' + content,
351
+ },
352
+ json: true,
353
+ });
354
+ }
355
+
320
356
  async run(comment, parent, disableAuthorNotify = false) {
321
357
  const { AUTHOR_EMAIL, BLOGGER_EMAIL } = process.env;
322
358
  const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
@@ -357,9 +393,11 @@ module.exports = class extends think.Service {
357
393
  const qq = await this.qq(comment, parent);
358
394
  const telegram = await this.telegram(comment, parent);
359
395
  const pushplus = await this.pushplus({ title, content }, comment, parent);
360
- console.log(pushplus);
396
+ const discord = await this.discord({ title, content }, comment, parent);
361
397
  if (
362
- [wechat, qq, telegram, qywxAmWechat, pushplus].every(think.isEmpty) &&
398
+ [wechat, qq, telegram, qywxAmWechat, pushplus, discord].every(
399
+ think.isEmpty
400
+ ) &&
363
401
  !isReplyAuthor
364
402
  ) {
365
403
  mailList.push({ to: AUTHOR, title, content });