@waline/vercel 1.31.13 → 1.31.14

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/Dockerfile CHANGED
@@ -6,10 +6,10 @@ RUN set -eux; \
6
6
  # npm config set registry https://registry.npm.taobao.org; \
7
7
  npm install --production --silent @waline/vercel
8
8
 
9
- FROM node:lts-buster-slim
9
+ FROM node:lts-slim
10
10
  WORKDIR /app
11
11
  ENV TZ Asia/Shanghai
12
12
  ENV NODE_ENV production
13
13
  COPY --from=build /app .
14
14
  EXPOSE 8360
15
- CMD ["node", "node_modules/@waline/vercel/vanilla.js"]
15
+ CMD ["node", "node_modules/@waline/vercel/vanilla.js"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.31.13",
3
+ "version": "1.31.14",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -17,26 +17,26 @@
17
17
  "dependencies": {
18
18
  "@cloudbase/node-sdk": "^2.11.0",
19
19
  "@koa/cors": "^5.0.0",
20
- "@mdit/plugin-katex": "^0.8.0",
21
- "@mdit/plugin-mathjax": "^0.4.8",
22
- "@mdit/plugin-sub": "^0.8.0",
23
- "@mdit/plugin-sup": "^0.8.0",
20
+ "@mdit/plugin-katex": "0.8.0",
21
+ "@mdit/plugin-mathjax": "0.4.8",
22
+ "@mdit/plugin-sub": "0.8.0",
23
+ "@mdit/plugin-sup": "0.8.0",
24
24
  "akismet": "^2.0.7",
25
25
  "deta": "^2.0.0",
26
- "dompurify": "^3.0.8",
26
+ "dompurify": "^3.1.3",
27
27
  "dy-node-ip2region": "^1.0.1",
28
28
  "fast-csv": "^5.0.1",
29
29
  "form-data": "^4.0.0",
30
30
  "jsdom": "^24.0.0",
31
31
  "jsonwebtoken": "^9.0.2",
32
- "katex": "^0.16.9",
32
+ "katex": "^0.16.10",
33
33
  "koa-compose": "^4.1.0",
34
34
  "leancloud-storage": "^4.15.2",
35
- "markdown-it": "^14.0.0",
35
+ "markdown-it": "^14.1.0",
36
36
  "markdown-it-emoji": "^3.0.0",
37
37
  "mathjax-full": "^3.2.2",
38
38
  "node-fetch": "^2.7.0",
39
- "nodemailer": "^6.9.9",
39
+ "nodemailer": "^6.9.13",
40
40
  "nunjucks": "^3.2.4",
41
41
  "phpass": "^0.1.1",
42
42
  "prismjs": "^1.29.0",
@@ -82,9 +82,7 @@ if (MONGO_DB) {
82
82
  }
83
83
 
84
84
  const isVercelPostgres =
85
- type === 'postgresql' &&
86
- POSTGRES_HOST &&
87
- POSTGRES_HOST.endsWith('vercel-storage.com');
85
+ type === 'postgresql' && POSTGRES_HOST?.endsWith('vercel-storage.com');
88
86
 
89
87
  exports.model = {
90
88
  type,
@@ -37,15 +37,11 @@ module.exports = class extends BaseRest {
37
37
 
38
38
  const data = [];
39
39
 
40
- for (let i = 0; i < path.length; i++) {
41
- const url = path[i];
40
+ for (const url of path) {
42
41
  let counters = {};
43
42
 
44
- for (let j = 0; j < type.length; j++) {
45
- const field = type[j];
46
-
47
- counters[field] =
48
- respObj[url] && respObj[url][field] ? respObj[url][field] : 0;
43
+ for (const field of type) {
44
+ counters[field] = respObj[url]?.[field] ? respObj[url][field] : 0;
49
45
  }
50
46
 
51
47
  if (type.length === 1 && deprecated) {
@@ -29,10 +29,9 @@ async function formatCmt(
29
29
  comment.label = user.label;
30
30
  }
31
31
 
32
- const avatarUrl =
33
- user && user.avatar
34
- ? user.avatar
35
- : await think.service('avatar').stringify(comment);
32
+ const avatarUrl = user?.avatar
33
+ ? user.avatar
34
+ : await think.service('avatar').stringify(comment);
36
35
 
37
36
  comment.avatar =
38
37
  avatarProxy && !avatarUrl.includes(avatarProxy)
@@ -568,6 +567,21 @@ module.exports = class extends BaseRest {
568
567
  .reverse(),
569
568
  );
570
569
 
570
+ const childCommentsMap = new Map();
571
+
572
+ childCommentsMap.set(cmt.objectId, cmt);
573
+ cmt.children.forEach((c) => childCommentsMap.set(c.objectId, c));
574
+
575
+ cmt.children.forEach((c) => {
576
+ const parent = childCommentsMap.get(c.pid);
577
+
578
+ c.reply_user = {
579
+ nick: parent.nick,
580
+ link: parent.link,
581
+ avatar: parent.avatar,
582
+ };
583
+ });
584
+
571
585
  return cmt;
572
586
  }),
573
587
  ),
@@ -14,8 +14,7 @@ module.exports = class extends BaseRest {
14
14
  },
15
15
  };
16
16
 
17
- for (let i = 0; i < exportData.tables.length; i++) {
18
- const tableName = exportData.tables[i];
17
+ for (const tableName of exportData.tables) {
19
18
  const model = this.getModel(tableName);
20
19
 
21
20
  const data = await model.select({});
@@ -57,7 +57,7 @@ module.exports = class extends think.Controller {
57
57
  },
58
58
  ).then((resp) => resp.json());
59
59
 
60
- if (!user || !user.id) {
60
+ if (!user?.id) {
61
61
  return this.fail(user);
62
62
  }
63
63
 
@@ -54,12 +54,12 @@ module.exports = class extends think.Controller {
54
54
  plugins.unshift(fn);
55
55
  }
56
56
 
57
- for (let i = 0; i < plugins.length; i++) {
58
- if (!think.isFunction(plugins[i])) {
57
+ for (const plugin of plugins) {
58
+ if (!think.isFunction(plugin)) {
59
59
  continue;
60
60
  }
61
61
 
62
- const resp = await plugins[i].call(this, ...args);
62
+ const resp = await plugin.call(this, ...args);
63
63
 
64
64
  if (resp) {
65
65
  return resp;
@@ -206,16 +206,15 @@ module.exports = class extends BaseRest {
206
206
  objectId: ['IN', userIds],
207
207
  });
208
208
 
209
- for (let i = 0; i < users.length; i++) {
210
- usersMap[users[i].objectId] = users;
209
+ for (const user of users) {
210
+ usersMap[user.objectId] = users;
211
211
  }
212
212
  }
213
213
 
214
214
  const users = [];
215
215
  const { avatarProxy } = this.config();
216
216
 
217
- for (let i = 0; i < counts.length; i++) {
218
- const count = counts[i];
217
+ for (const count of counts) {
219
218
  const user = {
220
219
  count: count.count,
221
220
  };
@@ -21,7 +21,7 @@ module.exports = {
21
21
  const { lang } = this.get();
22
22
  const locale = locales[(lang || 'zh-cn').toLowerCase()] || locales['zh-cn'];
23
23
 
24
- if (locale && locale[message]) {
24
+ if (locale?.[message]) {
25
25
  message = locale[message];
26
26
  }
27
27
 
@@ -92,10 +92,7 @@ module.exports = {
92
92
  uaParser(uaText) {
93
93
  const ua = parser(uaText);
94
94
 
95
- if (
96
- OS_VERSION_MAP[ua.os.name] &&
97
- OS_VERSION_MAP[ua.os.name][ua.os.version]
98
- ) {
95
+ if (OS_VERSION_MAP[ua.os.name]?.[ua.os.version]) {
99
96
  ua.os.version = OS_VERSION_MAP[ua.os.name][ua.os.version];
100
97
  }
101
98
 
@@ -121,10 +118,8 @@ module.exports = {
121
118
  return fns;
122
119
  }
123
120
 
124
- for (let i = 0; i < plugins.length; i++) {
125
- const plugin = plugins[i];
126
-
127
- if (!plugin || !plugin[type]) {
121
+ for (const plugin of plugins) {
122
+ if (!plugin?.[type]) {
128
123
  continue;
129
124
  }
130
125
 
@@ -1,3 +1,5 @@
1
+ const crypto = require('crypto');
2
+
1
3
  const nunjucks = require('nunjucks');
2
4
  const helper = require('think-helper');
3
5
 
@@ -6,6 +8,9 @@ const { GRAVATAR_STR } = process.env;
6
8
  const env = new nunjucks.Environment();
7
9
 
8
10
  env.addFilter('md5', (str) => helper.md5(str));
11
+ env.addFilter('sha256', (str) =>
12
+ crypto.createHash('sha256').update(str).digest('hex'),
13
+ );
9
14
 
10
15
  const DEFAULT_GRAVATAR_STR = `{%- set numExp = r/^[0-9]+$/g -%}
11
16
  {%- set qqMailExp = r/^[0-9]+@qq.com$/ig -%}
@@ -487,13 +487,14 @@ module.exports = class extends think.Service {
487
487
 
488
488
  const mailList = [];
489
489
  const isAuthorComment = AUTHOR
490
- ? comment.mail.toLowerCase() === AUTHOR.toLowerCase()
490
+ ? (comment.mail || '').toLowerCase() === AUTHOR.toLowerCase()
491
491
  : false;
492
492
  const isReplyAuthor = AUTHOR
493
- ? parent && parent.mail.toLowerCase() === AUTHOR.toLowerCase()
493
+ ? parent && (parent.mail || '').toLowerCase() === AUTHOR.toLowerCase()
494
494
  : false;
495
495
  const isCommentSelf =
496
- parent && parent.mail.toLowerCase() === comment.mail.toLowerCase();
496
+ parent &&
497
+ (parent.mail || '').toLowerCase() === (comment.mail || '').toLowerCase();
497
498
 
498
499
  const title = mailSubjectAdmin || 'MAIL_SUBJECT_ADMIN';
499
500
  const content = mailTemplateAdmin || 'MAIL_TEMPLATE_ADMIN';
@@ -539,9 +540,9 @@ module.exports = class extends think.Service {
539
540
  });
540
541
  }
541
542
 
542
- for (let i = 0; i < mailList.length; i++) {
543
+ for (const mail of mailList) {
543
544
  try {
544
- const response = await this.mail(mailList[i], comment, parent);
545
+ const response = await this.mail(mail, comment, parent);
545
546
 
546
547
  console.log('Notification mail send success: %s', response);
547
548
  } catch (e) {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
2
  /* eslint-disable no-unused-vars */
2
3
 
3
4
  module.exports = class extends think.Service {
@@ -254,18 +254,18 @@ module.exports = class extends Base {
254
254
  groupFlatValue[group] = null;
255
255
  });
256
256
 
257
- for (let j = 0; j < where._complex[groupName][1].length; j++) {
257
+ for (const item of where._complex[groupName][1]) {
258
258
  const groupWhere = {
259
259
  ...where,
260
260
  ...groupFlatValue,
261
261
  _complex: undefined,
262
- [groupName]: where._complex[groupName][1][j],
262
+ [groupName]: item,
263
263
  };
264
264
  const num = await this.count(groupWhere);
265
265
 
266
266
  counts.push({
267
267
  ...groupFlatValue,
268
- [groupName]: where._complex[groupName][1][j],
268
+ [groupName]: item,
269
269
  count: num,
270
270
  });
271
271
  }
@@ -320,6 +320,8 @@ module.exports = class extends Base {
320
320
 
321
321
  const counts = {};
322
322
 
323
+ // FIXME: The loop is weird @lizheming
324
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
323
325
  for (let i = 0; i < data.length; i++) {
324
326
  const key = group.map((field) => data[field]).join();
325
327
 
@@ -271,18 +271,16 @@ module.exports = class extends Base {
271
271
  const counts = await this.select(where, { field: options.group });
272
272
  const countsMap = {};
273
273
 
274
- for (let i = 0; i < counts.length; i++) {
274
+ for (const count of counts) {
275
275
  const key = options.group
276
- .map((item) => counts[i][item] || undefined)
276
+ .map((item) => count[item] || undefined)
277
277
  .join('_');
278
278
 
279
279
  if (!countsMap[key]) {
280
280
  countsMap[key] = {};
281
281
 
282
- for (let j = 0; j < options.group.length; j++) {
283
- const field = options.group[j];
284
-
285
- countsMap[key][field] = counts[i][field];
282
+ for (const field of options.group) {
283
+ countsMap[key][field] = count[field];
286
284
  }
287
285
  countsMap[key].count = 0;
288
286
  }
@@ -299,12 +297,12 @@ module.exports = class extends Base {
299
297
 
300
298
  const cacheDataMap = {};
301
299
 
302
- for (let i = 0; i < cacheData.length; i++) {
300
+ for (const item of cacheData) {
303
301
  const key = options.group
304
- .map((item) => cacheData[i][item] || undefined)
302
+ .map((item) => item[item] || undefined)
305
303
  .join('_');
306
304
 
307
- cacheDataMap[key] = cacheData[i];
305
+ cacheDataMap[key] = item;
308
306
  }
309
307
 
310
308
  const counts = [];
@@ -323,13 +321,13 @@ module.exports = class extends Base {
323
321
  groupFlatValue[group] = undefined;
324
322
  });
325
323
 
326
- for (let j = 0; j < where._complex[groupName][1].length; j++) {
324
+ for (const item of where._complex[groupName][1]) {
327
325
  const cacheKey = options.group
328
326
  .map(
329
327
  (item) =>
330
328
  ({
331
329
  ...groupFlatValue,
332
- [groupName]: where._complex[groupName][1][j],
330
+ [groupName]: item,
333
331
  })[item] || undefined,
334
332
  )
335
333
  .join('_');
@@ -342,7 +340,7 @@ module.exports = class extends Base {
342
340
  ...where,
343
341
  ...groupFlatValue,
344
342
  _complex: undefined,
345
- [groupName]: where._complex[groupName][1][j],
343
+ [groupName]: item,
346
344
  };
347
345
  const countPromise = this.count(groupWhere, {
348
346
  ...options,
@@ -350,7 +348,7 @@ module.exports = class extends Base {
350
348
  }).then((num) => {
351
349
  counts.push({
352
350
  ...groupFlatValue,
353
- [groupName]: where._complex[groupName][1][j],
351
+ [groupName]: item,
354
352
  count: num,
355
353
  });
356
354
  });
@@ -12,7 +12,7 @@ module.exports = class extends MySQL {
12
12
  lowerWhere[i.toLowerCase()] = where[i];
13
13
  }
14
14
 
15
- if (options && options.desc) {
15
+ if (options?.desc) {
16
16
  options.desc = options.desc.toLowerCase();
17
17
  }
18
18
 
package/.eslintrc.yml DELETED
@@ -1,13 +0,0 @@
1
- globals:
2
- think: readonly
3
-
4
- rules:
5
- import/no-commonjs:
6
- - off
7
-
8
- overrides:
9
- - files:
10
- - '__tests__/**/*.spec.js'
11
-
12
- parserOptions:
13
- sourceType: module