@waline/vercel 1.18.5 → 1.18.8

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.18.5",
3
+ "version": "1.18.8",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -15,38 +15,39 @@
15
15
  "license": "MIT",
16
16
  "author": "lizheming <i@imnerd.org>",
17
17
  "dependencies": {
18
- "@cloudbase/node-sdk": "^2.9.0",
19
- "@koa/cors": "^3.3.0",
20
- "akismet": "^2.0.7",
21
- "deta": "^1.1.0",
22
- "dompurify": "^2.3.6",
23
- "dy-node-ip2region": "^1.0.1",
24
- "fast-csv": "^4.3.6",
25
- "jsdom": "^19.0.0",
26
- "jsonwebtoken": "^8.5.1",
27
- "katex": "^0.15.3",
28
- "leancloud-storage": "^4.12.2",
29
- "markdown-it": "^13.0.1",
30
- "markdown-it-emoji": "^2.0.2",
31
- "markdown-it-sub": "^1.0.0",
32
- "markdown-it-sup": "^1.0.0",
33
- "mathjax-full": "^3.2.0",
34
- "nodemailer": "^6.7.5",
35
- "nunjucks": "^3.2.3",
36
- "phpass": "^0.1.1",
37
- "prismjs": "^1.28.0",
38
- "request": "^2.88.2",
39
- "request-promise-native": "^1.0.9",
40
- "speakeasy": "^2.0.0",
41
- "think-logger3": "^1.3.1",
42
- "think-model": "^1.5.4",
43
- "think-model-mysql": "^1.1.7",
18
+ "@cloudbase/node-sdk": "2.9.1",
19
+ "@koa/cors": "3.3.0",
20
+ "akismet": "2.0.7",
21
+ "deta": "1.1.0",
22
+ "dompurify": "2.3.8",
23
+ "dy-node-ip2region": "1.0.1",
24
+ "fast-csv": "4.3.6",
25
+ "jsdom": "19.0.0",
26
+ "jsonwebtoken": "8.5.1",
27
+ "katex": "0.16.0",
28
+ "leancloud-storage": "4.12.2",
29
+ "markdown-it": "13.0.1",
30
+ "markdown-it-emoji": "2.0.2",
31
+ "markdown-it-sub": "1.0.0",
32
+ "markdown-it-sup": "1.0.0",
33
+ "mathjax-full": "3.2.2",
34
+ "nodemailer": "6.7.5",
35
+ "nunjucks": "3.2.3",
36
+ "phpass": "0.1.1",
37
+ "prismjs": "1.28.0",
38
+ "request": "2.88.2",
39
+ "request-promise-native": "1.0.9",
40
+ "speakeasy": "2.0.0",
41
+ "think-helper": "^1.1.3",
42
+ "think-logger3": "1.3.1",
43
+ "think-model": "1.5.4",
44
+ "think-model-mysql": "1.1.7",
44
45
  "think-model-postgresql": "1.1.6",
45
- "think-model-sqlite": "^1.2.3",
46
- "think-mongo": "^2.2.1",
47
- "think-router-rest": "^1.0.5",
48
- "thinkjs": "^3.2.14",
49
- "ua-parser-js": "^1.0.2"
46
+ "think-model-sqlite": "1.2.3",
47
+ "think-mongo": "2.2.1",
48
+ "think-router-rest": "1.0.5",
49
+ "thinkjs": "3.2.14",
50
+ "ua-parser-js": "1.0.2"
50
51
  },
51
52
  "engines": {
52
53
  "node": ">=14"
@@ -640,7 +640,14 @@ module.exports = class extends BaseRest {
640
640
  return this.fail(preDeleteResp);
641
641
  }
642
642
 
643
- await this.modelInstance.delete({ objectId: this.id });
643
+ await this.modelInstance.delete({
644
+ _complex: {
645
+ _logic: 'or',
646
+ objectId: this.id,
647
+ pid: this.id,
648
+ rid: this.id,
649
+ },
650
+ });
644
651
  await this.hook('postDelete', this.id);
645
652
 
646
653
  return this.success();
@@ -3,6 +3,24 @@ const util = require('util');
3
3
  const BaseRest = require('./rest');
4
4
 
5
5
  const readFileAsync = util.promisify(fs.readFile);
6
+
7
+ function formatID(data, idGenerator) {
8
+ const objectIdMap = {};
9
+ for (let i = 0; i < data.length; i++) {
10
+ const { objectId } = data[i];
11
+ objectIdMap[objectId] = idGenerator(data[i], i, data);
12
+ }
13
+
14
+ for (let i = 0; i < data.length; i++) {
15
+ ['objectId', 'pid', 'rid']
16
+ .filter((k) => data[i][k])
17
+ .forEach((k) => {
18
+ data[i][k] = objectIdMap[data[i][k]];
19
+ });
20
+ }
21
+
22
+ return data;
23
+ }
6
24
  module.exports = class extends BaseRest {
7
25
  async getAction() {
8
26
  const exportData = {
@@ -43,11 +61,17 @@ module.exports = class extends BaseRest {
43
61
  const storage = this.config('storage');
44
62
  const model = this.service(`storage/${storage}`, tableName);
45
63
 
64
+ let data = importData.data[tableName];
65
+ if (['postgresql', 'mysql', 'sqlite'].includes(storage)) {
66
+ let i = 0;
67
+ data = formatID(data, () => (i = i + 1));
68
+ }
69
+
46
70
  // delete all data at first
47
71
  await model.delete({});
48
72
  // then add data one by one
49
- for (let j = 0; j < importData.data[tableName].length; j++) {
50
- await model.add(importData.data[tableName][j]);
73
+ for (let j = 0; j < data.length; j++) {
74
+ await model.add(data[j]);
51
75
  }
52
76
  }
53
77
  return this.success();
@@ -36,7 +36,7 @@ module.exports = class extends BaseRest {
36
36
  ? `"${SENDER_NAME}" <${SENDER_EMAIL}>`
37
37
  : SMTP_USER,
38
38
  to: user[0].email,
39
- subject: this.locale('[{{name}}] Reset Password', {
39
+ subject: this.locale('[{{name | safe}}] Reset Password', {
40
40
  name: SITE_NAME || 'Waline',
41
41
  }),
42
42
  html: this.locale(
@@ -89,7 +89,7 @@ module.exports = class extends BaseRest {
89
89
  ? `"${SENDER_NAME}" <${SENDER_EMAIL}>`
90
90
  : SMTP_USER,
91
91
  to: data.email,
92
- subject: this.locale('[{{name}}] Registration Confirm Mail', {
92
+ subject: this.locale('[{{name | safe}}] Registration Confirm Mail', {
93
93
  name: SITE_NAME || 'Waline',
94
94
  }),
95
95
  html: this.locale(
@@ -5,9 +5,9 @@
5
5
  "USER_REGISTED": "USER_REGISTED",
6
6
  "TOKEN_EXPIRED": "TOKEN_EXPIRED",
7
7
  "TWO_FACTOR_AUTH_ERROR_DETAIL": "TWO_FACTOR_AUTH_ERROR_DETAIL",
8
- "[{{name}}] Registration Confirm Mail": "[{{name}}] Registration Confirm Mail",
8
+ "[{{name | safe}}] Registration Confirm Mail": "[{{name | safe}}] Registration Confirm Mail",
9
9
  "Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.",
10
- "[{{name}}] Reset Password": "[{{name}}] Reset Password",
10
+ "[{{name | safe}}] Reset Password": "[{{name | safe}}] Reset Password",
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",
@@ -5,9 +5,9 @@
5
5
  "USER_REGISTED": "用户已注册",
6
6
  "TOKEN_EXPIRED": "密钥已过期",
7
7
  "TWO_FACTOR_AUTH_ERROR_DETAIL": "二步验证失败",
8
- "[{{name}}] Registration Confirm Mail": "【{{name}}】注册确认邮件",
8
+ "[{{name | safe}}] Registration Confirm Mail": "【{{name | safe}}】注册确认邮件",
9
9
  "Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "请点击 <a href=\"{{url}}\">{{url}}</a> 确认注册,链接有效时间为 1 个小时。如果不是你在注册,请忽略这封邮件。",
10
- "[{{name}}] Reset Password": "【{{name}}】重置密码",
10
+ "[{{name | safe}}] Reset Password": "【{{name | safe}}】重置密码",
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": "评论太快啦,请慢点!",
@@ -5,9 +5,9 @@
5
5
  "USER_REGISTED": "用戶已註冊",
6
6
  "TOKEN_EXPIRED": "密鑰已過期",
7
7
  "TWO_FACTOR_AUTH_ERROR_DETAIL": "二步驗證失敗",
8
- "[{{name}}] Registration Confirm Mail": "『{{name}}』註冊確認郵件",
8
+ "[{{name | safe}}] Registration Confirm Mail": "『{{name | safe}}』註冊確認郵件",
9
9
  "Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "請點擊 <a href=\"{{url}}\">{{url}}</a> 確認註冊,鏈接有效時間為 1 個小時。如果不是你在註冊,請忽略這封郵件。",
10
- "[{{name}}] Reset Password": "『{{name}}』重置密碼",
10
+ "[{{name | safe}}] Reset Password": "『{{name | safe}}』重置密碼",
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": "評論太快啦,請慢點!",
package/src/logic/base.js CHANGED
@@ -1,3 +1,4 @@
1
+ const path = require('path');
1
2
  const jwt = require('jsonwebtoken');
2
3
  const helper = require('think-helper');
3
4
 
@@ -8,6 +9,7 @@ module.exports = class extends think.Logic {
8
9
  `storage/${this.config('storage')}`,
9
10
  'Users'
10
11
  );
12
+ this.resource = this.getResource();
11
13
  this.id = this.getId();
12
14
  }
13
15
 
@@ -92,6 +94,13 @@ module.exports = class extends think.Logic {
92
94
  this.ctx.state.token = token;
93
95
  }
94
96
 
97
+ getResource() {
98
+ const filename = this.__filename || __filename;
99
+ const last = filename.lastIndexOf(path.sep);
100
+
101
+ return filename.substr(last + 1, filename.length - last - 4);
102
+ }
103
+
95
104
  getId() {
96
105
  const id = this.get('id');
97
106
 
@@ -13,6 +13,11 @@ module.exports = class extends Base {
13
13
  continue;
14
14
  }
15
15
 
16
+ if (k === '_complex') {
17
+ where[k] = this.parseWhere(filter[k]);
18
+ continue;
19
+ }
20
+
16
21
  if (filter[k] === undefined) {
17
22
  where[k] = null;
18
23
  continue;
@@ -23,6 +23,20 @@ module.exports = class extends MySQL {
23
23
  });
24
24
  }
25
25
 
26
+ async add(data) {
27
+ ['insertedAt', 'createdAt', 'updatedAt']
28
+ .filter((key) => data[key])
29
+ .forEach((key) => {
30
+ const val = data[key];
31
+ data[key.toLowerCase()] =
32
+ val instanceof Date
33
+ ? think.datetime(val, 'YYYY-MM-DD HH:mm:ss')
34
+ : val;
35
+ delete data[key];
36
+ });
37
+ return super.add(data);
38
+ }
39
+
26
40
  async count(...args) {
27
41
  let result = await super.count(...args);
28
42
  try {