@waline/vercel 1.19.3 → 1.19.4

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.19.3",
3
+ "version": "1.19.4",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -16,17 +16,17 @@
16
16
  "author": "lizheming <i@imnerd.org>",
17
17
  "dependencies": {
18
18
  "@cloudbase/node-sdk": "2.9.1",
19
- "@koa/cors": "3.3.0",
19
+ "@koa/cors": "3.4.1",
20
20
  "akismet": "2.0.7",
21
21
  "deta": "1.1.0",
22
- "dompurify": "2.3.10",
22
+ "dompurify": "2.4.0",
23
23
  "dy-node-ip2region": "1.0.1",
24
24
  "fast-csv": "4.3.6",
25
25
  "form-data": "4.0.0",
26
26
  "jsdom": "20.0.0",
27
27
  "jsonwebtoken": "8.5.1",
28
- "katex": "0.16.0",
29
- "leancloud-storage": "4.13.1",
28
+ "katex": "0.16.2",
29
+ "leancloud-storage": "4.13.2",
30
30
  "markdown-it": "13.0.1",
31
31
  "markdown-it-emoji": "2.0.2",
32
32
  "markdown-it-sub": "1.0.0",
@@ -36,9 +36,9 @@
36
36
  "nodemailer": "6.7.8",
37
37
  "nunjucks": "3.2.3",
38
38
  "phpass": "0.1.1",
39
- "prismjs": "1.28.0",
39
+ "prismjs": "1.29.0",
40
40
  "speakeasy": "2.0.0",
41
- "think-helper": "1.1.3",
41
+ "think-helper": "1.1.4",
42
42
  "think-logger3": "1.3.1",
43
43
  "think-model": "1.5.4",
44
44
  "think-model-mysql": "1.1.7",
@@ -54,7 +54,7 @@ if (LEAN_KEY) {
54
54
  storage = 'postgresql';
55
55
  jwtKey = jwtKey || PG_PASSWORD;
56
56
  } else if (SQLITE_PATH) {
57
- storage = 'mysql';
57
+ storage = 'sqlite';
58
58
  } else if (MYSQL_DB) {
59
59
  storage = 'mysql';
60
60
  jwtKey = jwtKey || MYSQL_PASSWORD;
@@ -145,7 +145,8 @@ module.exports = class extends BaseRest {
145
145
 
146
146
  case 'count': {
147
147
  const { url } = this.get();
148
- const where = { url: ['IN', url] };
148
+ const where =
149
+ Array.isArray(url) && url.length ? { url: ['IN', url] } : {};
149
150
 
150
151
  if (think.isEmpty(userInfo) || this.config('storage') === 'deta') {
151
152
  where.status = ['NOT IN', ['waiting', 'spam']];
@@ -156,12 +157,19 @@ module.exports = class extends BaseRest {
156
157
  user_id: userInfo.objectId,
157
158
  };
158
159
  }
159
- const data = await this.modelInstance.select(where, { field: ['url'] });
160
- const counts = url.map(
161
- (u) => data.filter(({ url }) => url === u).length
162
- );
163
160
 
164
- return this.json(counts.length === 1 ? counts[0] : counts);
161
+ if (Array.isArray(url) && url.length > 1) {
162
+ const data = await this.modelInstance.select(where, {
163
+ field: ['url'],
164
+ });
165
+
166
+ return this.json(
167
+ url.map((u) => data.filter(({ url }) => url === u).length)
168
+ );
169
+ }
170
+ const data = await this.modelInstance.count(where);
171
+
172
+ return this.json(data);
165
173
  }
166
174
 
167
175
  case 'list': {
@@ -76,12 +76,15 @@ module.exports = class extends BaseRest {
76
76
  let i = 0;
77
77
 
78
78
  data = formatID(data, () => (i = i + 1));
79
- } else if (storage === 'leancloud') {
80
- data
81
- .filter(({ insertedAt }) => insertedAt)
82
- .forEach((item) => {
83
- item.insertedAt = new Date(item.insertedAt);
84
- });
79
+ await model.setSeqId(1);
80
+ }
81
+
82
+ if (storage === 'leancloud' || storage === 'mysql') {
83
+ data.forEach((item) => {
84
+ item.insertedAt && (item.insertedAt = new Date(item.insertedAt));
85
+ item.createdAt && (item.createdAt = new Date(item.createdAt));
86
+ item.updatedAt && (item.updatedAt = new Date(item.updatedAt));
87
+ });
85
88
  }
86
89
 
87
90
  // delete all data at first
@@ -113,7 +116,7 @@ module.exports = class extends BaseRest {
113
116
  const oldId = cmt[field];
114
117
  const newId = idMaps[tableName].get(cmt[field]);
115
118
 
116
- if (oldId !== newId) {
119
+ if (oldId && newId && oldId !== newId) {
117
120
  willUpdateItem[field] = newId;
118
121
  }
119
122
  });
@@ -89,7 +89,7 @@ module.exports = class extends Base {
89
89
  * @apiGroup Comment
90
90
  * @apiVersion 0.0.1
91
91
  *
92
- * @apiParam {String} url a array string join by comma just like `a` or `a,b`
92
+ * @apiParam {String} url a array string join by comma just like `a` or `a,b`, return site comment count if url empty
93
93
  *
94
94
  * @apiSuccessExample {Number} Single Path Response:
95
95
  * 300
@@ -131,7 +131,6 @@ module.exports = class extends Base {
131
131
  this.rules = {
132
132
  url: {
133
133
  array: true,
134
- required: true,
135
134
  },
136
135
  };
137
136
  break;
@@ -144,12 +144,11 @@ module.exports = class extends think.Service {
144
144
  querystring.set('corpsecret', `${QYWX_AM_AY[1]}`);
145
145
 
146
146
  const { access_token } = await fetch(
147
- `https://qyapi.weixin.qq.com/cgi-bin/gettoken`,
147
+ `https://qyapi.weixin.qq.com/cgi-bin/gettoken?${querystring.toString()}`,
148
148
  {
149
149
  headers: {
150
150
  'content-type': 'application/json',
151
151
  },
152
- body: querystring,
153
152
  }
154
153
  ).then((resp) => resp.json());
155
154
 
@@ -392,6 +391,8 @@ module.exports = class extends think.Service {
392
391
  const isReplyAuthor = AUTHOR
393
392
  ? parent && parent.mail.toLowerCase() === AUTHOR.toLowerCase()
394
393
  : false;
394
+ const isCommentSelf =
395
+ parent && parent.mail.toLowerCase() === comment.mail.toLowerCase();
395
396
 
396
397
  const title = mailSubjectAdmin || '{{site.name | safe}} 上有新评论了';
397
398
  const content =
@@ -436,7 +437,12 @@ module.exports = class extends think.Service {
436
437
  );
437
438
  const fakeMail = new RegExp(`@(${disallowList.join('|')})$`, 'i');
438
439
 
439
- if (parent && !fakeMail.test(parent.mail) && comment.status !== 'waiting') {
440
+ if (
441
+ parent &&
442
+ !fakeMail.test(parent.mail) &&
443
+ !isCommentSelf &&
444
+ comment.status !== 'waiting'
445
+ ) {
440
446
  mailList.push({
441
447
  to: parent.mail,
442
448
  title:
@@ -113,4 +113,12 @@ module.exports = class extends Base {
113
113
 
114
114
  return instance.where(this.parseWhere(where)).delete();
115
115
  }
116
+
117
+ async setSeqId(id) {
118
+ const instance = this.model(this.tableName);
119
+
120
+ return instance.query(
121
+ `ALTER TABLE ${instance.tableName} AUTO_INCREMENT = ${id};`
122
+ );
123
+ }
116
124
  };
@@ -73,4 +73,12 @@ module.exports = class extends MySQL {
73
73
 
74
74
  return result;
75
75
  }
76
+
77
+ async setSeqId(id) {
78
+ const instance = this.model(this.tableName);
79
+
80
+ return instance.query(
81
+ `ALTER SEQUENCE ${instance.tableName}_seq RESTART WITH ${id};`
82
+ );
83
+ }
76
84
  };
@@ -0,0 +1,11 @@
1
+ const MySQL = require('./mysql');
2
+
3
+ module.exports = class extends MySQL {
4
+ async setSeqId(id) {
5
+ const instance = this.model(this.tableName);
6
+
7
+ return instance.query(
8
+ `UPDATE SQLITE_SEQUENCE SET SEQ=${id} WHERE NAME='${instance.tableName}';`
9
+ );
10
+ }
11
+ };