@waline/vercel 1.18.9 → 1.19.2

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.
@@ -35,6 +35,7 @@ module.exports = class extends BaseRest {
35
35
  }
36
36
 
37
37
  const twoFactorAuthSecret = user[0]['2fa'];
38
+
38
39
  if (twoFactorAuthSecret) {
39
40
  const verified = speakeasy.totp.verify({
40
41
  secret: twoFactorAuthSecret,
@@ -42,6 +43,7 @@ module.exports = class extends BaseRest {
42
43
  token: code,
43
44
  window: 2,
44
45
  });
46
+
45
47
  if (!verified) {
46
48
  return this.fail();
47
49
  }
@@ -55,10 +57,12 @@ module.exports = class extends BaseRest {
55
57
  link: user[0].url,
56
58
  });
57
59
  const { avatarProxy } = think.config();
60
+
58
61
  if (avatarProxy) {
59
62
  avatarUrl = avatarProxy + '?url=' + encodeURIComponent(avatarUrl);
60
63
  }
61
64
  user[0].avatar = avatarUrl;
65
+
62
66
  return this.success({
63
67
  ...user[0],
64
68
  password: null,
@@ -12,6 +12,7 @@ module.exports = class extends BaseRest {
12
12
  SITE_NAME,
13
13
  } = process.env;
14
14
  const hasMailServie = SMTP_HOST || SMTP_SERVICE;
15
+
15
16
  if (!hasMailServie) {
16
17
  return this.fail();
17
18
  }
@@ -22,6 +23,7 @@ module.exports = class extends BaseRest {
22
23
  'Users'
23
24
  );
24
25
  const user = await userModel.select({ email });
26
+
25
27
  if (think.isEmpty(user)) {
26
28
  return this.fail();
27
29
  }
@@ -23,6 +23,7 @@ module.exports = class extends BaseRest {
23
23
  offset: Math.max((page - 1) * pageSize, 0),
24
24
  }
25
25
  );
26
+
26
27
  return this.success({
27
28
  page,
28
29
  totalPages: Math.ceil(count / pageSize),
@@ -147,8 +148,10 @@ module.exports = class extends BaseRest {
147
148
  }
148
149
 
149
150
  const socials = ['github', 'twitter', 'facebook', 'google', 'weibo', 'qq'];
151
+
150
152
  socials.forEach((social) => {
151
153
  const nextSocial = this.post(social);
154
+
152
155
  if (think.isString(nextSocial)) {
153
156
  updateData[social] = nextSocial;
154
157
  }
@@ -12,18 +12,21 @@ module.exports = class extends BaseRest {
12
12
  async getAction() {
13
13
  const { token, email } = this.get();
14
14
  const users = await this.modelInstance.select({ email });
15
+
15
16
  if (think.isEmpty(users)) {
16
17
  return this.fail(this.locale('USER_NOT_EXIST'));
17
18
  }
18
19
 
19
20
  const user = users[0];
20
21
  const match = user.type.match(/^verify:(\d{4}):(\d+)$/i);
22
+
21
23
  if (!match) {
22
24
  return this.fail(this.locale('USER_REGISTED'));
23
25
  }
24
26
 
25
27
  if (token === match[1] && Date.now() < parseInt(match[2])) {
26
28
  await this.modelInstance.update({ type: 'guest' }, { email });
29
+
27
30
  return this.redirect('/ui/login');
28
31
  }
29
32
 
@@ -4,18 +4,22 @@ const locales = require('../locales');
4
4
  module.exports = {
5
5
  success(...args) {
6
6
  this.ctx.success(...args);
7
+
7
8
  return think.prevent();
8
9
  },
9
10
  fail(...args) {
10
11
  this.ctx.fail(...args);
12
+
11
13
  return think.prevent();
12
14
  },
13
15
  locale(message, variables) {
14
16
  const { lang } = this.get();
15
17
  const locale = locales[(lang || '').toLowerCase()];
18
+
16
19
  if (locale && locale[message]) {
17
20
  message = locale[message];
18
21
  }
22
+
19
23
  return nunjucks.renderString(message, variables);
20
24
  },
21
25
  };
@@ -14,9 +14,11 @@ module.exports = {
14
14
  findLastIndex(arr, fn) {
15
15
  for (let i = arr.length - 1; i >= 0; i--) {
16
16
  const ret = fn(arr[i], i, arr);
17
+
17
18
  if (!ret) {
18
19
  continue;
19
20
  }
21
+
20
22
  return i;
21
23
  }
22
24
 
@@ -34,6 +36,7 @@ module.exports = {
34
36
 
35
37
  function runTask() {
36
38
  const idx = index;
39
+
37
40
  index += 1;
38
41
  if (index > promises.length) {
39
42
  return Promise.resolve();
@@ -45,6 +48,7 @@ module.exports = {
45
48
  if (count === promises.length) {
46
49
  resolve(ret);
47
50
  }
51
+
48
52
  return runTask();
49
53
  }, reject);
50
54
  }
@@ -60,15 +64,18 @@ module.exports = {
60
64
  try {
61
65
  const search = helper.promisify(regionSearch.btreeSearch, regionSearch);
62
66
  const result = await search(ip);
67
+
63
68
  if (!result) {
64
69
  return '';
65
70
  }
66
71
  const { region } = result;
67
72
  const [, , province, city, isp] = region.split('|');
68
73
  const address = Array.from(new Set([province, city, isp]));
74
+
69
75
  return address.slice(0, depth).join(' ');
70
76
  } catch (e) {
71
77
  console.log(e);
78
+
72
79
  return '';
73
80
  }
74
81
  },
package/src/logic/base.js CHANGED
@@ -16,6 +16,7 @@ module.exports = class extends think.Logic {
16
16
  async __before() {
17
17
  const referrer = this.ctx.referrer(true);
18
18
  let { secureDomains } = this.config();
19
+
19
20
  if (secureDomains && referrer && this.ctx.host.indexOf(referrer) !== 0) {
20
21
  secureDomains = think.isArray(secureDomains)
21
22
  ? secureDomains
@@ -33,6 +34,7 @@ module.exports = class extends think.Logic {
33
34
  ? domain.test(referrer)
34
35
  : domain === referrer
35
36
  );
37
+
36
38
  if (!match) {
37
39
  return this.ctx.throw(403);
38
40
  }
@@ -41,11 +43,13 @@ module.exports = class extends think.Logic {
41
43
  this.ctx.state.userInfo = {};
42
44
  const { authorization } = this.ctx.req.headers;
43
45
  const { state } = this.get();
46
+
44
47
  if (!authorization && !state) {
45
48
  return;
46
49
  }
47
50
  const token = state || authorization.replace(/^Bearer /, '');
48
51
  const userMail = jwt.verify(token, think.config('jwtKey'));
52
+
49
53
  if (think.isEmpty(userMail) || !think.isString(userMail)) {
50
54
  return;
51
55
  }
@@ -71,6 +75,7 @@ module.exports = class extends think.Logic {
71
75
  ],
72
76
  }
73
77
  );
78
+
74
79
  if (think.isEmpty(user)) {
75
80
  return;
76
81
  }
@@ -85,6 +90,7 @@ module.exports = class extends think.Logic {
85
90
  link: userInfo.url,
86
91
  });
87
92
  const { avatarProxy } = think.config();
93
+
88
94
  if (avatarProxy) {
89
95
  avatarUrl = avatarProxy + '?url=' + encodeURIComponent(avatarUrl);
90
96
  }
@@ -1,4 +1,5 @@
1
1
  const Base = require('./base');
2
+
2
3
  module.exports = class extends Base {
3
4
  async __before() {
4
5
  await super.__before();
@@ -7,6 +8,7 @@ module.exports = class extends Base {
7
8
  const { like } = this.post();
8
9
  const isAllowedGet = this.isGet && (type !== 'list' || path);
9
10
  const isAllowedPut = this.ctx.isMethod('PUT') && think.isBoolean(like);
11
+
10
12
  if (this.isPost || isAllowedGet || isAllowedPut) {
11
13
  return;
12
14
  }
@@ -114,6 +116,7 @@ module.exports = class extends Base {
114
116
  */
115
117
  getAction() {
116
118
  const { type } = this.get();
119
+
117
120
  switch (type) {
118
121
  case 'recent':
119
122
  this.rules = {
@@ -135,6 +138,7 @@ module.exports = class extends Base {
135
138
 
136
139
  case 'list': {
137
140
  const { userInfo } = this.ctx.state;
141
+
138
142
  if (userInfo.type !== 'administrator') {
139
143
  return this.fail();
140
144
  }
@@ -224,6 +228,7 @@ module.exports = class extends Base {
224
228
  */
225
229
  putAction() {
226
230
  const { userInfo } = this.ctx.state;
231
+
227
232
  if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
228
233
  this.rules = {
229
234
  like: {
package/src/logic/db.js CHANGED
@@ -5,6 +5,7 @@ module.exports = class extends Base {
5
5
  await super.__before(...args);
6
6
 
7
7
  const { userInfo } = this.ctx.state;
8
+
8
9
  if (think.isEmpty(userInfo)) {
9
10
  return this.fail(401);
10
11
  }
@@ -12,6 +12,7 @@ module.exports = class extends Base {
12
12
 
13
13
  async postAction() {
14
14
  const { userInfo } = this.ctx.state;
15
+
15
16
  if (think.isEmpty(userInfo)) {
16
17
  return this.fail(401);
17
18
  }
package/src/logic/user.js CHANGED
@@ -3,6 +3,7 @@ const Base = require('./base');
3
3
  module.exports = class extends Base {
4
4
  getAction() {
5
5
  const { userInfo } = this.ctx.state;
6
+
6
7
  if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
7
8
  return this.fail();
8
9
  }
@@ -50,6 +51,7 @@ module.exports = class extends Base {
50
51
  putAction() {
51
52
  // you need login to update yourself profile
52
53
  const { userInfo } = this.ctx.state;
54
+
53
55
  if (think.isEmpty(userInfo)) {
54
56
  return this.fail();
55
57
  }
@@ -3,6 +3,7 @@ const DEFAULT_KEY = '70542d86693e';
3
3
 
4
4
  module.exports = function (comment, blog) {
5
5
  let { AKISMET_KEY, SITE_URL } = process.env;
6
+
6
7
  if (!AKISMET_KEY) {
7
8
  AKISMET_KEY = DEFAULT_KEY;
8
9
  }
@@ -3,6 +3,7 @@ const helper = require('think-helper');
3
3
  const { GRAVATAR_STR } = process.env;
4
4
 
5
5
  const env = new nunjucks.Environment();
6
+
6
7
  env.addFilter('md5', (str) => helper.md5(str));
7
8
 
8
9
  const DEFAULT_GRAVATAR_STR = `{%- set numExp = r/^[0-9]+$/g -%}
@@ -14,17 +15,21 @@ const DEFAULT_GRAVATAR_STR = `{%- set numExp = r/^[0-9]+$/g -%}
14
15
  {%- else -%}
15
16
  https://seccdn.libravatar.org/avatar/{{mail|md5}}
16
17
  {%- endif -%}`;
18
+
17
19
  module.exports = class extends think.Service {
18
20
  async stringify(comment) {
19
21
  const fn = think.config('avatarUrl');
22
+
20
23
  if (think.isFunction(fn)) {
21
24
  const ret = await fn(comment);
25
+
22
26
  if (think.isString(ret) && ret) {
23
27
  return ret;
24
28
  }
25
29
  }
26
30
 
27
31
  const gravatarStr = GRAVATAR_STR || DEFAULT_GRAVATAR_STR;
32
+
28
33
  return env.renderString(gravatarStr, comment);
29
34
  }
30
35
  };
@@ -9,6 +9,7 @@ const katexInline = (tex, options) => {
9
9
  return katex.renderToString(tex, options);
10
10
  } catch (error) {
11
11
  if (options.throwOnError) console.warn(error);
12
+
12
13
  return `<span class='katex-error' title='${escapeHtml(
13
14
  error.toString()
14
15
  )}'>${escapeHtml(tex)}</span>`;
@@ -21,6 +22,7 @@ const katexBlock = (tex, options) => {
21
22
  return `<p class='katex-block'>${katex.renderToString(tex, options)}</p>`;
22
23
  } catch (error) {
23
24
  if (options.throwOnError) console.warn(error);
25
+
24
26
  return `<p class='katex-block katex-error' title='${escapeHtml(
25
27
  error.toString()
26
28
  )}'>${escapeHtml(tex)}</p>`;
@@ -5,6 +5,7 @@
5
5
  const isValidDelim = (state, pos) => {
6
6
  const prevChar = pos > 0 ? state.src.charAt(pos - 1) : '';
7
7
  const nextChar = pos + 1 <= state.posMax ? state.src.charAt(pos + 1) : '';
8
+
8
9
  return {
9
10
  canOpen: nextChar !== ' ' && nextChar !== '\t',
10
11
  /*
@@ -31,6 +32,7 @@ const inlineTex = (state, silent) => {
31
32
  if (!res.canOpen) {
32
33
  if (!silent) state.pending += '$';
33
34
  state.pos += 1;
35
+
34
36
  return true;
35
37
  }
36
38
  /*
@@ -58,6 +60,7 @@ const inlineTex = (state, silent) => {
58
60
  if (match === -1) {
59
61
  if (!silent) state.pending += '$';
60
62
  state.pos = start;
63
+
61
64
  return true;
62
65
  }
63
66
 
@@ -65,6 +68,7 @@ const inlineTex = (state, silent) => {
65
68
  if (match - start === 0) {
66
69
  if (!silent) state.pending += '$$';
67
70
  state.pos = start + 1;
71
+
68
72
  return true;
69
73
  }
70
74
 
@@ -74,6 +78,7 @@ const inlineTex = (state, silent) => {
74
78
  if (!res.canClose) {
75
79
  if (!silent) state.pending += '$';
76
80
  state.pos = start;
81
+
77
82
  return true;
78
83
  }
79
84
 
@@ -12,6 +12,7 @@ const { inlineTex, blockTex } = require('./mathCommon');
12
12
  class MathToSvg {
13
13
  constructor() {
14
14
  const adaptor = liteAdaptor();
15
+
15
16
  RegisterHTMLHandler(adaptor);
16
17
 
17
18
  const packages = AllPackages.sort();
@@ -27,6 +28,7 @@ class MathToSvg {
27
28
 
28
29
  if (svg.includes('data-mml-node="merror"')) {
29
30
  const errorTitle = svg.match(/<title>(.*?)<\/title>/)[1];
31
+
30
32
  svg = `<span class='katex-error' title='${escapeHtml(
31
33
  errorTitle
32
34
  )}'>${escapeHtml(tex)}</span>`;
@@ -41,6 +43,7 @@ class MathToSvg {
41
43
 
42
44
  if (svg.includes('data-mml-node="merror"')) {
43
45
  const errorTitle = svg.match(/<title>(.*?)<\/title>/)[1];
46
+
44
47
  svg = `<p class='katex-block katex-error' title='${escapeHtml(
45
48
  errorTitle
46
49
  )}'>${escapeHtml(tex)}</p>`;