@waline/vercel 1.7.0 → 1.8.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- ## @waline/vercel
1
+ # @waline/vercel
2
2
 
3
- ![](https://img.shields.io/npm/v/@waline/vercel?color=blue&logo=npm&style=flat-square)
3
+ ![Version](https://img.shields.io/npm/v/@waline/vercel?color=blue&logo=npm&style=flat-square)
4
4
 
5
5
  This is the backend for Waline comment system.
6
6
 
@@ -20,6 +20,6 @@ We support [Akismet](https://akismet.com/) spam protection service default. If y
20
20
 
21
21
  ## Deploy
22
22
 
23
- [ ![](https://vercel.com/button) ](https://vercel.com/import/project?template=https://github.com/walinejs/waline/tree/main/example)
23
+ [![Deploy button](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/walinejs/waline/tree/main/example)
24
24
 
25
25
  Click it to deploy quickly!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "repository": "https://github.com/walinejs/waline",
6
6
  "license": "MIT",
@@ -10,25 +10,25 @@
10
10
  "@cloudbase/node-sdk": "^2.7.1",
11
11
  "@koa/cors": "^3.1.0",
12
12
  "akismet": "^2.0.6",
13
- "deta": "^1.0.1",
14
- "dompurify": "^2.3.3",
13
+ "deta": "^1.0.2",
14
+ "dompurify": "^2.3.6",
15
15
  "fast-csv": "^4.3.6",
16
- "jsdom": "^18.0.0",
16
+ "jsdom": "^19.0.0",
17
17
  "jsonwebtoken": "^8.5.1",
18
- "katex": "^0.13.23",
19
- "leancloud-storage": "^4.12.0",
18
+ "katex": "^0.15.2",
19
+ "leancloud-storage": "^4.12.2",
20
20
  "markdown-it": "^12.3.2",
21
21
  "markdown-it-emoji": "^2.0.0",
22
22
  "markdown-it-sub": "^1.0.0",
23
23
  "markdown-it-sup": "^1.0.0",
24
24
  "mathjax-full": "^3.2.0",
25
- "nodemailer": "^6.7.0",
25
+ "nodemailer": "^6.7.2",
26
26
  "nunjucks": "^3.2.3",
27
27
  "phpass": "^0.1.1",
28
- "prismjs": "^1.25.0",
28
+ "prismjs": "^1.27.0",
29
29
  "request": "^2.88.2",
30
30
  "request-promise-native": "^1.0.9",
31
- "think-logger3": "^1.2.1",
31
+ "think-logger3": "^1.3.1",
32
32
  "think-model": "^1.5.4",
33
33
  "think-model-mysql": "^1.1.6",
34
34
  "think-model-postgresql": "^1.1.6",
@@ -36,6 +36,6 @@
36
36
  "think-mongo": "^2.1.2",
37
37
  "think-router-rest": "^1.0.5",
38
38
  "thinkjs": "^3.2.14",
39
- "ua-parser-js": "^0.7.31"
39
+ "ua-parser-js": "^1.0.2"
40
40
  }
41
41
  }
@@ -37,10 +37,9 @@ const {
37
37
  } = process.env;
38
38
 
39
39
  let type = 'common';
40
- let mongoOpt = {
41
- replicaSet: MONGO_REPLICASET,
42
- authSource: MONGO_AUTHSOURCE,
43
- };
40
+ const mongoOpt = {};
41
+ if (MONGO_REPLICASET) mongoOpt.replicaSet = MONGO_REPLICASET;
42
+ if (MONGO_AUTHSOURCE) mongoOpt.authSource = MONGO_AUTHSOURCE;
44
43
 
45
44
  if (MONGO_DB) {
46
45
  type = 'mongo';
@@ -28,10 +28,16 @@ DOMPurify.addHook('afterSanitizeAttributes', function (node) {
28
28
  });
29
29
 
30
30
  const sanitize = (content) =>
31
- DOMPurify.sanitize(content, {
32
- FORBID_TAGS: ['form', 'input', 'style'],
33
- FORBID_ATTR: ['autoplay', 'style'],
34
- });
31
+ DOMPurify.sanitize(
32
+ content,
33
+ Object.assign(
34
+ {
35
+ FORBID_TAGS: ['form', 'input', 'style'],
36
+ FORBID_ATTR: ['autoplay', 'style'],
37
+ },
38
+ think.config('domPurify') || {}
39
+ )
40
+ );
35
41
 
36
42
  module.exports = {
37
43
  sanitize,
@@ -273,6 +273,50 @@ module.exports = class extends think.Service {
273
273
  });
274
274
  }
275
275
 
276
+ async pushplus({ title, content }, self, parent) {
277
+ const {
278
+ PUSH_PLUS_KEY,
279
+ PUSH_PLUS_TOPIC: topic,
280
+ PUSH_PLUS_TEMPLATE: template,
281
+ PUSH_PLUS_CHANNEL: channel,
282
+ PUSH_PLUS_WEBHOOK: webhook,
283
+ PUSH_PLUS_CALLBACKURL: callbackUrl,
284
+ SITE_NAME,
285
+ SITE_URL,
286
+ } = process.env;
287
+
288
+ if (!PUSH_PLUS_KEY) {
289
+ return false;
290
+ }
291
+
292
+ const data = {
293
+ self,
294
+ parent,
295
+ site: {
296
+ name: SITE_NAME,
297
+ url: SITE_URL,
298
+ postUrl: SITE_URL + self.url + '#' + self.objectId,
299
+ },
300
+ };
301
+ title = nunjucks.renderString(title, data);
302
+ content = nunjucks.renderString(content, data);
303
+
304
+ return request({
305
+ uri: `http://www.pushplus.plus/send/${PUSH_PLUS_KEY}`,
306
+ method: 'POST',
307
+ form: {
308
+ title,
309
+ content,
310
+ topic,
311
+ template,
312
+ channel,
313
+ webhook,
314
+ callbackUrl,
315
+ },
316
+ json: true,
317
+ });
318
+ }
319
+
276
320
  async run(comment, parent, disableAuthorNotify = false) {
277
321
  const { AUTHOR_EMAIL, BLOGGER_EMAIL } = process.env;
278
322
  const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
@@ -312,11 +356,10 @@ module.exports = class extends think.Service {
312
356
  );
313
357
  const qq = await this.qq(comment, parent);
314
358
  const telegram = await this.telegram(comment, parent);
359
+ const pushplus = await this.pushplus({ title, content }, comment, parent);
360
+ console.log(pushplus);
315
361
  if (
316
- think.isEmpty(wechat) &&
317
- think.isEmpty(qq) &&
318
- think.isEmpty(telegram) &&
319
- think.isEmpty(qywxAmWechat) &&
362
+ [wechat, qq, telegram, qywxAmWechat, pushplus].every(think.isEmpty) &&
320
363
  !isReplyAuthor
321
364
  ) {
322
365
  mailList.push({ to: AUTHOR, title, content });