@waline/vercel 1.28.2 → 1.29.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.28.2",
3
+ "version": "1.29.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -15,40 +15,40 @@
15
15
  "license": "MIT",
16
16
  "author": "lizheming <i@imnerd.org>",
17
17
  "dependencies": {
18
- "@cloudbase/node-sdk": "2.9.1",
19
- "@koa/cors": "4.0.0",
20
- "akismet": "2.0.7",
21
- "deta": "1.1.0",
22
- "dompurify": "3.0.1",
23
- "dy-node-ip2region": "1.0.1",
24
- "fast-csv": "4.3.6",
25
- "form-data": "4.0.0",
26
- "jsdom": "21.1.1",
27
- "jsonwebtoken": "9.0.0",
28
- "katex": "0.16.4",
29
- "leancloud-storage": "4.14.0",
30
- "markdown-it": "13.0.1",
31
- "markdown-it-emoji": "2.0.2",
32
- "markdown-it-sub": "1.0.0",
33
- "markdown-it-sup": "1.0.0",
34
- "mathjax-full": "3.2.2",
35
- "node-fetch": "2.6.9",
36
- "nodemailer": "6.9.1",
37
- "nunjucks": "3.2.3",
38
- "phpass": "0.1.1",
39
- "prismjs": "1.29.0",
40
- "speakeasy": "2.0.0",
41
- "think-helper": "1.1.4",
42
- "think-logger3": "1.3.1",
43
- "think-model": "1.5.4",
44
- "think-model-mysql": "1.1.7",
18
+ "@cloudbase/node-sdk": "^2.9.1",
19
+ "@koa/cors": "^4.0.0",
20
+ "akismet": "^2.0.7",
21
+ "deta": "^1.1.0",
22
+ "dompurify": "^3.0.1",
23
+ "dy-node-ip2region": "^1.0.1",
24
+ "fast-csv": "^4.3.6",
25
+ "form-data": "^4.0.0",
26
+ "jsdom": "^21.1.1",
27
+ "jsonwebtoken": "^9.0.0",
28
+ "katex": "^0.16.4",
29
+ "leancloud-storage": "^4.14.0",
30
+ "markdown-it": "^13.0.1",
31
+ "markdown-it-emoji": "^2.0.2",
32
+ "markdown-it-sub": "^1.0.0",
33
+ "markdown-it-sup": "^1.0.0",
34
+ "mathjax-full": "^3.2.2",
35
+ "node-fetch": "^2.6.9",
36
+ "nodemailer": "^6.9.1",
37
+ "nunjucks": "^3.2.3",
38
+ "phpass": "^0.1.1",
39
+ "prismjs": "^1.29.0",
40
+ "speakeasy": "^2.0.0",
41
+ "think-helper": "^1.1.4",
42
+ "think-logger3": "^1.3.1",
43
+ "think-model": "^1.5.4",
44
+ "think-model-mysql": "^1.1.7",
45
45
  "think-model-mysql2": "^2.0.0",
46
46
  "think-model-postgresql": "1.1.7",
47
- "think-model-sqlite": "1.3.1",
48
- "think-mongo": "2.2.1",
49
- "think-router-rest": "1.0.5",
50
- "thinkjs": "3.2.14",
51
- "ua-parser-js": "1.0.34"
47
+ "think-model-sqlite": "^1.3.1",
48
+ "think-mongo": "^2.2.1",
49
+ "think-router-rest": "^1.0.5",
50
+ "thinkjs": "^3.2.14",
51
+ "ua-parser-js": "^1.0.35"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=14"
@@ -27,7 +27,9 @@ module.exports = class extends BaseRest {
27
27
  return o;
28
28
  }, {});
29
29
 
30
- return this.jsonOrSuccess((type.length === 1 && deprecated) ? data[type[0]] : data);
30
+ return this.jsonOrSuccess(
31
+ type.length === 1 && deprecated ? data[type[0]] : data
32
+ );
31
33
  }
32
34
 
33
35
  const respObj = resp.reduce((o, n) => {
@@ -61,7 +61,7 @@ async function formatCmt(
61
61
  if (typeof comment.sticky === 'string') {
62
62
  comment.sticky = Boolean(Number(comment.sticky));
63
63
  }
64
-
64
+
65
65
  comment.time = new Date(comment.insertedAt).getTime();
66
66
  if (!deprecated) {
67
67
  delete comment.insertedAt;
@@ -150,7 +150,12 @@ module.exports = class extends BaseRest {
150
150
  return this.jsonOrSuccess(
151
151
  await Promise.all(
152
152
  comments.map((cmt) =>
153
- formatCmt(cmt, users, { ...this.config(), deprecated: this.ctx.state.deprecated }, userInfo)
153
+ formatCmt(
154
+ cmt,
155
+ users,
156
+ { ...this.config(), deprecated: this.ctx.state.deprecated },
157
+ userInfo
158
+ )
154
159
  )
155
160
  )
156
161
  );
@@ -256,7 +261,12 @@ module.exports = class extends BaseRest {
256
261
  waitingCount,
257
262
  data: await Promise.all(
258
263
  comments.map((cmt) =>
259
- formatCmt(cmt, users, { ...this.config(), deprecated: this.ctx.state.deprecated }, userInfo)
264
+ formatCmt(
265
+ cmt,
266
+ users,
267
+ { ...this.config(), deprecated: this.ctx.state.deprecated },
268
+ userInfo
269
+ )
260
270
  )
261
271
  ),
262
272
  });
@@ -449,7 +459,7 @@ module.exports = class extends BaseRest {
449
459
  comment,
450
460
  users,
451
461
  { ...this.config(), deprecated: this.ctx.state.deprecated },
452
- userInfo,
462
+ userInfo
453
463
  );
454
464
 
455
465
  cmt.children = await Promise.all(
@@ -656,7 +666,12 @@ module.exports = class extends BaseRest {
656
666
  think.logger.debug(`Comment post hooks postSave done!`);
657
667
 
658
668
  return this.success(
659
- await formatCmt(resp, [userInfo], { ...this.config(), deprecated: this.ctx.state.deprecated }, userInfo)
669
+ await formatCmt(
670
+ resp,
671
+ [userInfo],
672
+ { ...this.config(), deprecated: this.ctx.state.deprecated },
673
+ userInfo
674
+ )
660
675
  );
661
676
  }
662
677
 
@@ -28,6 +28,7 @@ module.exports = class extends think.Controller {
28
28
  lang: params.get('lng'),
29
29
  serverURL: location.protocol + '//' + location.host + location.pathname.replace(/\\/+$/, ''),
30
30
  recaptchaV3Key: '${process.env.RECAPTCHA_V3_KEY || ''}',
31
+ turnstileKey: '${process.env.TURNSTILE_KEY || ''}',
31
32
  });
32
33
  </script>
33
34
  </body>
package/src/logic/base.js CHANGED
@@ -135,30 +135,64 @@ module.exports = class extends think.Logic {
135
135
  }
136
136
 
137
137
  async useCaptchaCheck() {
138
- const { RECAPTCHA_V3_SECRET } = process.env;
138
+ const { RECAPTCHA_V3_SECRET, TURNSTILE_SECRET } = process.env;
139
+ const { turnstile, recaptchaV3 } = this.post();
140
+
141
+ if (TURNSTILE_SECRET) {
142
+ return this.useRecaptchaOrTurnstileCheck({
143
+ secret: TURNSTILE_SECRET,
144
+ token: turnstile,
145
+ api: 'https://challenges.cloudflare.com/turnstile/v0/siteverify',
146
+ method: 'POST',
147
+ });
148
+ }
149
+
150
+ if (RECAPTCHA_V3_SECRET) {
151
+ return this.useRecaptchaOrTurnstileCheck({
152
+ secret: RECAPTCHA_V3_SECRET,
153
+ token: recaptchaV3,
154
+ api: 'https://recaptcha.net/recaptcha/api/siteverify',
155
+ method: 'GET',
156
+ });
157
+ }
158
+ }
139
159
 
140
- if (!RECAPTCHA_V3_SECRET) {
160
+ async useRecaptchaOrTurnstileCheck({ secret, token, api, method }) {
161
+ if (!secret) {
141
162
  return;
142
163
  }
143
- const { recaptchaV3 } = this.post();
144
164
 
145
- if (!recaptchaV3) {
165
+ if (!token) {
146
166
  return this.ctx.throw(403);
147
167
  }
148
168
 
149
169
  const query = qs.stringify({
150
- secret: RECAPTCHA_V3_SECRET,
151
- response: recaptchaV3,
170
+ secret,
171
+ response: token,
152
172
  remoteip: this.ctx.ip,
153
173
  });
154
- const recaptchaV3Result = await fetch(
155
- `https://recaptcha.net/recaptcha/api/siteverify?${query}`
156
- ).then((resp) => resp.json());
157
174
 
158
- if (!recaptchaV3Result.success) {
175
+ const requestUrl = method === 'GET' ? api + '?' + query : api;
176
+ const options =
177
+ method === 'GET'
178
+ ? {}
179
+ : {
180
+ method,
181
+ headers: {
182
+ 'content-type':
183
+ 'application/x-www-form-urlencoded; charset=UTF-8',
184
+ },
185
+ body: query,
186
+ };
187
+
188
+ const response = await fetch(requestUrl, options).then((resp) =>
189
+ resp.json()
190
+ );
191
+
192
+ if (!response.success) {
159
193
  think.logger.debug(
160
- 'RecaptchaV3 Result:',
161
- JSON.stringify(recaptchaV3Result, null, '\t')
194
+ 'RecaptchaV3 or Turnstile Result:',
195
+ JSON.stringify(response, null, '\t')
162
196
  );
163
197
 
164
198
  return this.ctx.throw(403);
@@ -13,6 +13,7 @@ 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
  window.recaptchaV3Key = ${JSON.stringify(process.env.RECAPTCHA_V3_KEY)};
16
+ window.turnstileKey = ${JSON.stringify(process.env.TURNSTILE_KEY)};
16
17
  window.serverURL = '${ctx.serverURL}/api/';
17
18
  </script>
18
19
  <script src="${