@waline/vercel 1.16.0 → 1.17.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.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -26,15 +26,15 @@
26
26
  "jsonwebtoken": "^8.5.1",
27
27
  "katex": "^0.15.3",
28
28
  "leancloud-storage": "^4.12.2",
29
- "markdown-it": "^12.3.2",
30
- "markdown-it-emoji": "^2.0.0",
29
+ "markdown-it": "^13.0.1",
30
+ "markdown-it-emoji": "^2.0.2",
31
31
  "markdown-it-sub": "^1.0.0",
32
32
  "markdown-it-sup": "^1.0.0",
33
33
  "mathjax-full": "^3.2.0",
34
- "nodemailer": "^6.7.3",
34
+ "nodemailer": "^6.7.4",
35
35
  "nunjucks": "^3.2.3",
36
36
  "phpass": "^0.1.1",
37
- "prismjs": "^1.27.0",
37
+ "prismjs": "^1.28.0",
38
38
  "request": "^2.88.2",
39
39
  "request-promise-native": "^1.0.9",
40
40
  "speakeasy": "^2.0.0",
@@ -107,7 +107,7 @@ module.exports = {
107
107
  disallowIPList: [],
108
108
  secureDomains: SECURE_DOMAINS ? SECURE_DOMAINS.split(/\s*,\s*/) : undefined,
109
109
  disableUserAgent: DISABLE_USERAGENT && !isFalse(DISABLE_USERAGENT),
110
- disableReigon: DISABLE_REGION && !isFalse(DISABLE_REGION),
110
+ disableRegion: DISABLE_REGION && !isFalse(DISABLE_REGION),
111
111
  levels:
112
112
  !LEVELS || isFalse(LEVELS)
113
113
  ? false
@@ -25,6 +25,7 @@ async function formatCmt(
25
25
  comment.mail = user.email;
26
26
  comment.link = user.url;
27
27
  comment.type = user.type;
28
+ comment.label = user.label;
28
29
  }
29
30
 
30
31
  const avatarUrl =
@@ -112,7 +113,14 @@ module.exports = class extends BaseRest {
112
113
  users = await userModel.select(
113
114
  { objectId: ['IN', user_ids] },
114
115
  {
115
- field: ['display_name', 'email', 'url', 'type', 'avatar'],
116
+ field: [
117
+ 'display_name',
118
+ 'email',
119
+ 'url',
120
+ 'type',
121
+ 'avatar',
122
+ 'label',
123
+ ],
116
124
  }
117
125
  );
118
126
  }
@@ -192,7 +200,14 @@ module.exports = class extends BaseRest {
192
200
  users = await userModel.select(
193
201
  { objectId: ['IN', user_ids] },
194
202
  {
195
- field: ['display_name', 'email', 'url', 'type', 'avatar'],
203
+ field: [
204
+ 'display_name',
205
+ 'email',
206
+ 'url',
207
+ 'type',
208
+ 'avatar',
209
+ 'label',
210
+ ],
196
211
  }
197
212
  );
198
213
  }
@@ -314,7 +329,14 @@ module.exports = class extends BaseRest {
314
329
  users = await userModel.select(
315
330
  { objectId: ['IN', user_ids] },
316
331
  {
317
- field: ['display_name', 'email', 'url', 'type', 'avatar'],
332
+ field: [
333
+ 'display_name',
334
+ 'email',
335
+ 'url',
336
+ 'type',
337
+ 'avatar',
338
+ 'label',
339
+ ],
318
340
  }
319
341
  );
320
342
  }
@@ -11,6 +11,26 @@ module.exports = class extends BaseRest {
11
11
  );
12
12
  }
13
13
 
14
+ async getAction() {
15
+ const { page, pageSize } = this.get();
16
+
17
+ const count = await this.modelInstance.count({});
18
+ const users = await this.modelInstance.select(
19
+ {},
20
+ {
21
+ desc: 'insertedAt',
22
+ limit: pageSize,
23
+ offset: Math.max((page - 1) * pageSize, 0),
24
+ }
25
+ );
26
+ return this.success({
27
+ page,
28
+ totalPages: Math.ceil(count / pageSize),
29
+ pageSize,
30
+ data: users,
31
+ });
32
+ }
33
+
14
34
  async postAction() {
15
35
  const data = this.post();
16
36
  const resp = await this.modelInstance.select({
@@ -92,12 +112,20 @@ module.exports = class extends BaseRest {
92
112
  }
93
113
 
94
114
  async putAction() {
95
- const { display_name, url, avatar, password } = this.post();
115
+ const { display_name, url, avatar, password, type, label } = this.post();
96
116
  const { objectId } = this.ctx.state.userInfo;
97
117
  const twoFactorAuth = this.post('2fa');
98
118
 
99
119
  const updateData = {};
100
120
 
121
+ if (this.id && type) {
122
+ updateData.type = type;
123
+ }
124
+
125
+ if (think.isString(label)) {
126
+ updateData.label = label;
127
+ }
128
+
101
129
  if (display_name) {
102
130
  updateData.display_name = display_name;
103
131
  }
@@ -130,7 +158,9 @@ module.exports = class extends BaseRest {
130
158
  return this.success();
131
159
  }
132
160
 
133
- await this.modelInstance.update(updateData, { objectId });
161
+ await this.modelInstance.update(updateData, {
162
+ objectId: this.id || objectId,
163
+ });
134
164
 
135
165
  return this.success();
136
166
  }
@@ -56,12 +56,12 @@ module.exports = {
56
56
  try {
57
57
  const search = helper.promisify(regionSearch.btreeSearch, regionSearch);
58
58
  const { region } = await search(ip);
59
- const [,, province, city, isp] = region.split('|');
59
+ const [, , province, city, isp] = region.split('|');
60
60
  const address = Array.from(new Set([province, city, isp]));
61
61
  return address.slice(0, depth).join(' ');
62
- } catch(e) {
62
+ } catch (e) {
63
63
  console.log(e);
64
64
  return '';
65
65
  }
66
- }
66
+ },
67
67
  };
package/src/logic/base.js CHANGED
@@ -8,6 +8,7 @@ module.exports = class extends think.Logic {
8
8
  `storage/${this.config('storage')}`,
9
9
  'Users'
10
10
  );
11
+ this.id = this.getId();
11
12
  }
12
13
 
13
14
  async __before() {
@@ -89,4 +90,20 @@ module.exports = class extends think.Logic {
89
90
  this.ctx.state.userInfo = userInfo;
90
91
  this.ctx.state.token = token;
91
92
  }
93
+
94
+ getId() {
95
+ const id = this.get('id');
96
+
97
+ if (id && (think.isString(id) || think.isNumber(id))) {
98
+ return id;
99
+ }
100
+
101
+ const last = decodeURIComponent(this.ctx.path.split('/').pop());
102
+
103
+ if (last !== this.resource && /^([a-z0-9]+,?)*$/i.test(last)) {
104
+ return last;
105
+ }
106
+
107
+ return '';
108
+ }
92
109
  };
package/src/logic/user.js CHANGED
@@ -1,6 +1,24 @@
1
1
  const Base = require('./base');
2
2
 
3
3
  module.exports = class extends Base {
4
+ getAction() {
5
+ const { userInfo } = this.ctx.state;
6
+ if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
7
+ return this.fail();
8
+ }
9
+
10
+ this.rules = {
11
+ page: {
12
+ int: true,
13
+ default: 1,
14
+ },
15
+ pageSize: {
16
+ int: { max: 100 },
17
+ default: 10,
18
+ },
19
+ };
20
+ }
21
+
4
22
  /**
5
23
  * @api {POST} /user user register
6
24
  * @apiGroup User
@@ -30,9 +48,15 @@ module.exports = class extends Base {
30
48
  * @apiSuccess (200) {String} errmsg return error message if error
31
49
  */
32
50
  putAction() {
51
+ // you need login to update yourself profile
33
52
  const { userInfo } = this.ctx.state;
34
53
  if (think.isEmpty(userInfo)) {
35
54
  return this.fail();
36
55
  }
56
+
57
+ // you should be a administrator to update otherself info
58
+ if (this.id && userInfo.type !== 'administrator') {
59
+ return this.fail();
60
+ }
37
61
  }
38
62
  };