@waline/vercel 1.36.3 → 1.36.5
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/__tests__/xss.spec.js +8 -19
- package/package.json +16 -17
- package/src/config/adapter.js +2 -7
- package/src/config/config.js +2 -10
- package/src/config/extend.js +0 -6
- package/src/config/middleware.js +2 -5
- package/src/controller/article.js +3 -10
- package/src/controller/comment.js +14 -37
- package/src/controller/db.js +3 -9
- package/src/controller/oauth.js +2 -5
- package/src/controller/user/password.js +3 -12
- package/src/controller/user.js +10 -38
- package/src/extend/think.js +2 -6
- package/src/logic/base.js +7 -25
- package/src/logic/user.js +1 -1
- package/src/service/avatar.js +1 -3
- package/src/service/markdown/mathCommon.js +2 -8
- package/src/service/markdown/mathjax.js +1 -2
- package/src/service/notify.js +66 -92
- package/src/service/storage/base.js +1 -6
- package/src/service/storage/github.js +15 -24
- package/src/service/storage/leancloud.js +13 -33
- package/src/service/storage/mongodb.js +1 -2
- package/src/service/storage/mysql.js +3 -9
- package/src/service/storage/postgresql.js +2 -6
- package/src/service/storage/deta.js +0 -310
package/src/logic/base.js
CHANGED
|
@@ -28,9 +28,7 @@ module.exports = class extends think.Logic {
|
|
|
28
28
|
let { secureDomains } = this.config();
|
|
29
29
|
|
|
30
30
|
if (secureDomains) {
|
|
31
|
-
secureDomains = think.isArray(secureDomains)
|
|
32
|
-
? secureDomains
|
|
33
|
-
: [secureDomains];
|
|
31
|
+
secureDomains = think.isArray(secureDomains) ? secureDomains : [secureDomains];
|
|
34
32
|
|
|
35
33
|
secureDomains.push(
|
|
36
34
|
'localhost',
|
|
@@ -49,19 +47,11 @@ module.exports = class extends think.Logic {
|
|
|
49
47
|
secureDomains = secureDomains
|
|
50
48
|
.map((domain) => {
|
|
51
49
|
// 如果是正则表达式字符串,创建一个 RegExp 对象
|
|
52
|
-
if (
|
|
53
|
-
typeof domain === 'string' &&
|
|
54
|
-
domain.startsWith('/') &&
|
|
55
|
-
domain.endsWith('/')
|
|
56
|
-
) {
|
|
50
|
+
if (typeof domain === 'string' && domain.startsWith('/') && domain.endsWith('/')) {
|
|
57
51
|
try {
|
|
58
52
|
return new RegExp(domain.slice(1, -1)); // 去掉斜杠并创建 RegExp 对象
|
|
59
53
|
} catch (e) {
|
|
60
|
-
console.error(
|
|
61
|
-
'Invalid regex pattern in secureDomains:',
|
|
62
|
-
domain,
|
|
63
|
-
e,
|
|
64
|
-
);
|
|
54
|
+
console.error('Invalid regex pattern in secureDomains:', domain, e);
|
|
65
55
|
|
|
66
56
|
return null;
|
|
67
57
|
}
|
|
@@ -74,9 +64,7 @@ module.exports = class extends think.Logic {
|
|
|
74
64
|
// 有 referrer 检查 referrer,没有则检查 origin
|
|
75
65
|
const checking = referrer ? referrer : origin;
|
|
76
66
|
const isSafe = secureDomains.some((domain) =>
|
|
77
|
-
think.isFunction(domain.test)
|
|
78
|
-
? domain.test(checking)
|
|
79
|
-
: domain === checking,
|
|
67
|
+
think.isFunction(domain.test) ? domain.test(checking) : domain === checking,
|
|
80
68
|
);
|
|
81
69
|
|
|
82
70
|
if (!isSafe) {
|
|
@@ -212,21 +200,15 @@ module.exports = class extends think.Logic {
|
|
|
212
200
|
: {
|
|
213
201
|
method,
|
|
214
202
|
headers: {
|
|
215
|
-
'content-type':
|
|
216
|
-
'application/x-www-form-urlencoded; charset=UTF-8',
|
|
203
|
+
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
217
204
|
},
|
|
218
205
|
body: query,
|
|
219
206
|
};
|
|
220
207
|
|
|
221
|
-
const response = await fetch(requestUrl, options).then((resp) =>
|
|
222
|
-
resp.json(),
|
|
223
|
-
);
|
|
208
|
+
const response = await fetch(requestUrl, options).then((resp) => resp.json());
|
|
224
209
|
|
|
225
210
|
if (!response.success) {
|
|
226
|
-
think.logger.debug(
|
|
227
|
-
'RecaptchaV3 or Turnstile Result:',
|
|
228
|
-
JSON.stringify(response, null, '\t'),
|
|
229
|
-
);
|
|
211
|
+
think.logger.debug('RecaptchaV3 or Turnstile Result:', JSON.stringify(response, null, '\t'));
|
|
230
212
|
|
|
231
213
|
return this.ctx.throw(403);
|
|
232
214
|
}
|
package/src/logic/user.js
CHANGED
package/src/service/avatar.js
CHANGED
|
@@ -8,9 +8,7 @@ const { GRAVATAR_STR } = process.env;
|
|
|
8
8
|
const env = new nunjucks.Environment();
|
|
9
9
|
|
|
10
10
|
env.addFilter('md5', (str) => helper.md5(str));
|
|
11
|
-
env.addFilter('sha256', (str) =>
|
|
12
|
-
crypto.createHash('sha256').update(str).digest('hex'),
|
|
13
|
-
);
|
|
11
|
+
env.addFilter('sha256', (str) => crypto.createHash('sha256').update(str).digest('hex'));
|
|
14
12
|
|
|
15
13
|
const DEFAULT_GRAVATAR_STR = `{%- set numExp = r/^[0-9]+$/g -%}
|
|
16
14
|
{%- set qqMailExp = r/^[0-9]+@qq.com$/ig -%}
|
|
@@ -12,11 +12,7 @@ const isValidDelim = (state, pos) => {
|
|
|
12
12
|
* Check non-whitespace conditions for opening and closing, and
|
|
13
13
|
* check that closing delimiter isn’t followed by a number
|
|
14
14
|
*/
|
|
15
|
-
canClose: !(
|
|
16
|
-
prevChar === ' ' ||
|
|
17
|
-
prevChar === '\t' ||
|
|
18
|
-
/[0-9]/u.exec(nextChar)
|
|
19
|
-
),
|
|
15
|
+
canClose: !(prevChar === ' ' || prevChar === '\t' || /[0-9]/u.exec(nextChar)),
|
|
20
16
|
};
|
|
21
17
|
};
|
|
22
18
|
|
|
@@ -141,9 +137,7 @@ const blockTeX = (state, start, end, silent) => {
|
|
|
141
137
|
? `${firstLine}\n`
|
|
142
138
|
: '') +
|
|
143
139
|
state.getLines(start + 1, next, state.tShift[start], true) +
|
|
144
|
-
((lastLine === null || lastLine === void 0 ? void 0 : lastLine.trim())
|
|
145
|
-
? lastLine
|
|
146
|
-
: '');
|
|
140
|
+
((lastLine === null || lastLine === void 0 ? void 0 : lastLine.trim()) ? lastLine : '');
|
|
147
141
|
token.map = [start, state.line];
|
|
148
142
|
token.markup = '$$';
|
|
149
143
|
|
|
@@ -60,8 +60,7 @@ const mathjaxPlugin = (md) => {
|
|
|
60
60
|
|
|
61
61
|
md.renderer.rules.inlineTeX = (tokens, idx) => inline(tokens[idx].content);
|
|
62
62
|
|
|
63
|
-
md.renderer.rules.blockTeX = (tokens, idx) =>
|
|
64
|
-
`${block(tokens[idx].content)}\n`;
|
|
63
|
+
md.renderer.rules.blockTeX = (tokens, idx) => `${block(tokens[idx].content)}\n`;
|
|
65
64
|
};
|
|
66
65
|
|
|
67
66
|
module.exports = {
|
package/src/service/notify.js
CHANGED
|
@@ -9,14 +9,7 @@ module.exports = class extends think.Service {
|
|
|
9
9
|
super(controller);
|
|
10
10
|
|
|
11
11
|
this.controller = controller;
|
|
12
|
-
const {
|
|
13
|
-
SMTP_USER,
|
|
14
|
-
SMTP_PASS,
|
|
15
|
-
SMTP_HOST,
|
|
16
|
-
SMTP_PORT,
|
|
17
|
-
SMTP_SECURE,
|
|
18
|
-
SMTP_SERVICE,
|
|
19
|
-
} = process.env;
|
|
12
|
+
const { SMTP_USER, SMTP_PASS, SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_SERVICE } = process.env;
|
|
20
13
|
|
|
21
14
|
if (SMTP_HOST || SMTP_SERVICE) {
|
|
22
15
|
const config = {
|
|
@@ -43,8 +36,7 @@ module.exports = class extends think.Service {
|
|
|
43
36
|
return;
|
|
44
37
|
}
|
|
45
38
|
|
|
46
|
-
const { SITE_NAME, SITE_URL, SMTP_USER, SENDER_EMAIL, SENDER_NAME } =
|
|
47
|
-
process.env;
|
|
39
|
+
const { SITE_NAME, SITE_URL, SMTP_USER, SENDER_EMAIL, SENDER_NAME } = process.env;
|
|
48
40
|
const data = {
|
|
49
41
|
self,
|
|
50
42
|
parent,
|
|
@@ -59,10 +51,7 @@ module.exports = class extends think.Service {
|
|
|
59
51
|
content = this.controller.locale(content, data);
|
|
60
52
|
|
|
61
53
|
return this.transporter.sendMail({
|
|
62
|
-
from:
|
|
63
|
-
SENDER_EMAIL && SENDER_NAME
|
|
64
|
-
? `"${SENDER_NAME}" <${SENDER_EMAIL}>`
|
|
65
|
-
: SMTP_USER,
|
|
54
|
+
from: SENDER_EMAIL && SENDER_NAME ? `"${SENDER_NAME}" <${SENDER_EMAIL}>` : SMTP_USER,
|
|
66
55
|
to,
|
|
67
56
|
subject: title,
|
|
68
57
|
html: content,
|
|
@@ -110,8 +99,7 @@ module.exports = class extends think.Service {
|
|
|
110
99
|
}
|
|
111
100
|
|
|
112
101
|
async qywxAmWechat({ title, content }, self, parent) {
|
|
113
|
-
const { QYWX_AM, QYWX_PROXY, QYWX_PROXY_PORT, SITE_NAME, SITE_URL } =
|
|
114
|
-
process.env;
|
|
102
|
+
const { QYWX_AM, QYWX_PROXY, QYWX_PROXY_PORT, SITE_NAME, SITE_URL } = process.env;
|
|
115
103
|
|
|
116
104
|
if (!QYWX_AM) {
|
|
117
105
|
return false;
|
|
@@ -165,41 +153,35 @@ module.exports = class extends think.Service {
|
|
|
165
153
|
}
|
|
166
154
|
}
|
|
167
155
|
|
|
168
|
-
const { access_token } = await fetch(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
headers: {
|
|
172
|
-
'content-type': 'application/json',
|
|
173
|
-
},
|
|
156
|
+
const { access_token } = await fetch(`${baseUrl}/cgi-bin/gettoken?${querystring.toString()}`, {
|
|
157
|
+
headers: {
|
|
158
|
+
'content-type': 'application/json',
|
|
174
159
|
},
|
|
175
|
-
).then((resp) => resp.json());
|
|
176
|
-
|
|
177
|
-
return fetch(
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
|
|
181
|
-
headers: {
|
|
182
|
-
'content-type': 'application/json',
|
|
183
|
-
},
|
|
184
|
-
body: JSON.stringify({
|
|
185
|
-
touser: `${QYWX_AM_AY[2]}`,
|
|
186
|
-
agentid: `${QYWX_AM_AY[3]}`,
|
|
187
|
-
msgtype: 'mpnews',
|
|
188
|
-
mpnews: {
|
|
189
|
-
articles: [
|
|
190
|
-
{
|
|
191
|
-
title,
|
|
192
|
-
thumb_media_id: `${QYWX_AM_AY[4]}`,
|
|
193
|
-
author: `Waline Comment`,
|
|
194
|
-
content_source_url: `${data.site.postUrl}`,
|
|
195
|
-
content: `${content}`,
|
|
196
|
-
digest: `${desp}`,
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
},
|
|
200
|
-
}),
|
|
160
|
+
}).then((resp) => resp.json());
|
|
161
|
+
|
|
162
|
+
return fetch(`${baseUrl}/cgi-bin/message/send?access_token=${access_token}`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: {
|
|
165
|
+
'content-type': 'application/json',
|
|
201
166
|
},
|
|
202
|
-
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
touser: `${QYWX_AM_AY[2]}`,
|
|
169
|
+
agentid: `${QYWX_AM_AY[3]}`,
|
|
170
|
+
msgtype: 'mpnews',
|
|
171
|
+
mpnews: {
|
|
172
|
+
articles: [
|
|
173
|
+
{
|
|
174
|
+
title,
|
|
175
|
+
thumb_media_id: `${QYWX_AM_AY[4]}`,
|
|
176
|
+
author: `Waline Comment`,
|
|
177
|
+
content_source_url: `${data.site.postUrl}`,
|
|
178
|
+
content: `${content}`,
|
|
179
|
+
digest: `${desp}`,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
}),
|
|
184
|
+
}).then((resp) => resp.json());
|
|
203
185
|
}
|
|
204
186
|
|
|
205
187
|
async qq(self, parent) {
|
|
@@ -209,9 +191,7 @@ module.exports = class extends think.Service {
|
|
|
209
191
|
return false;
|
|
210
192
|
}
|
|
211
193
|
|
|
212
|
-
const comment = self.comment
|
|
213
|
-
.replace(/<a href="(.*?)">(.*?)<\/a>/g, '')
|
|
214
|
-
.replace(/<[^>]+>/g, '');
|
|
194
|
+
const comment = self.comment.replace(/<a href="(.*?)">(.*?)<\/a>/g, '').replace(/<[^>]+>/g, '');
|
|
215
195
|
|
|
216
196
|
const data = {
|
|
217
197
|
self: {
|
|
@@ -233,20 +213,29 @@ module.exports = class extends think.Service {
|
|
|
233
213
|
{{self.comment}}
|
|
234
214
|
仅供预览评论,请前往上述页面查看完整內容。`;
|
|
235
215
|
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
form.append('msg', this.controller.locale(contentQQ, data));
|
|
239
|
-
form.append('qq', QQ_ID);
|
|
216
|
+
const qmsgHost = QMSG_HOST ? QMSG_HOST.replace(/\/$/, '') : 'https://qmsg.zendee.cn';
|
|
240
217
|
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
:
|
|
218
|
+
const postBodyData = {
|
|
219
|
+
qq: QQ_ID,
|
|
220
|
+
msg: this.controller.locale(contentQQ, data),
|
|
221
|
+
};
|
|
222
|
+
const postBody = Object.keys(postBodyData)
|
|
223
|
+
.map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(postBodyData[key]))
|
|
224
|
+
.join('&');
|
|
244
225
|
|
|
245
226
|
return fetch(`${qmsgHost}/send/${QMSG_KEY}`, {
|
|
246
227
|
method: 'POST',
|
|
247
|
-
headers:
|
|
248
|
-
|
|
249
|
-
|
|
228
|
+
headers: {
|
|
229
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
230
|
+
},
|
|
231
|
+
body: postBody,
|
|
232
|
+
}).then((resp) => {
|
|
233
|
+
return resp.json().then((json) => {
|
|
234
|
+
think.logger.debug(`qq notify response: ${JSON.stringify(json)}`);
|
|
235
|
+
|
|
236
|
+
return json;
|
|
237
|
+
});
|
|
238
|
+
});
|
|
250
239
|
}
|
|
251
240
|
|
|
252
241
|
async telegram(self, parent) {
|
|
@@ -306,20 +295,17 @@ module.exports = class extends think.Service {
|
|
|
306
295
|
},
|
|
307
296
|
};
|
|
308
297
|
|
|
309
|
-
const resp = await fetch(
|
|
310
|
-
|
|
311
|
-
{
|
|
312
|
-
|
|
313
|
-
headers: {
|
|
314
|
-
'Content-Type': 'application/json',
|
|
315
|
-
},
|
|
316
|
-
body: JSON.stringify({
|
|
317
|
-
chat_id: TG_CHAT_ID,
|
|
318
|
-
text: this.controller.locale(contentTG, data),
|
|
319
|
-
parse_mode: 'MarkdownV2',
|
|
320
|
-
}),
|
|
298
|
+
const resp = await fetch(`https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`, {
|
|
299
|
+
method: 'POST',
|
|
300
|
+
headers: {
|
|
301
|
+
'Content-Type': 'application/json',
|
|
321
302
|
},
|
|
322
|
-
|
|
303
|
+
body: JSON.stringify({
|
|
304
|
+
chat_id: TG_CHAT_ID,
|
|
305
|
+
text: this.controller.locale(contentTG, data),
|
|
306
|
+
parse_mode: 'MarkdownV2',
|
|
307
|
+
}),
|
|
308
|
+
}).then((resp) => resp.json());
|
|
323
309
|
|
|
324
310
|
if (!resp.ok) {
|
|
325
311
|
console.log('Telegram Notification Failed:' + JSON.stringify(resp));
|
|
@@ -492,8 +478,7 @@ module.exports = class extends think.Service {
|
|
|
492
478
|
|
|
493
479
|
async run(comment, parent, disableAuthorNotify = false) {
|
|
494
480
|
const { AUTHOR_EMAIL, DISABLE_AUTHOR_NOTIFY } = process.env;
|
|
495
|
-
const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } =
|
|
496
|
-
think.config();
|
|
481
|
+
const { mailSubject, mailTemplate, mailSubjectAdmin, mailTemplateAdmin } = think.config();
|
|
497
482
|
const AUTHOR = AUTHOR_EMAIL;
|
|
498
483
|
|
|
499
484
|
const mailList = [];
|
|
@@ -504,37 +489,26 @@ module.exports = class extends think.Service {
|
|
|
504
489
|
? parent && (parent.mail || '').toLowerCase() === AUTHOR.toLowerCase()
|
|
505
490
|
: false;
|
|
506
491
|
const isCommentSelf =
|
|
507
|
-
parent &&
|
|
508
|
-
(parent.mail || '').toLowerCase() === (comment.mail || '').toLowerCase();
|
|
492
|
+
parent && (parent.mail || '').toLowerCase() === (comment.mail || '').toLowerCase();
|
|
509
493
|
|
|
510
494
|
const title = mailSubjectAdmin || 'MAIL_SUBJECT_ADMIN';
|
|
511
495
|
const content = mailTemplateAdmin || 'MAIL_TEMPLATE_ADMIN';
|
|
512
496
|
|
|
513
497
|
if (!DISABLE_AUTHOR_NOTIFY && !isAuthorComment && !disableAuthorNotify) {
|
|
514
498
|
const wechat = await this.wechat({ title, content }, comment, parent);
|
|
515
|
-
const qywxAmWechat = await this.qywxAmWechat(
|
|
516
|
-
{ title, content },
|
|
517
|
-
comment,
|
|
518
|
-
parent,
|
|
519
|
-
);
|
|
499
|
+
const qywxAmWechat = await this.qywxAmWechat({ title, content }, comment, parent);
|
|
520
500
|
const qq = await this.qq(comment, parent);
|
|
521
501
|
const telegram = await this.telegram(comment, parent);
|
|
522
502
|
const pushplus = await this.pushplus({ title, content }, comment, parent);
|
|
523
503
|
const discord = await this.discord({ title, content }, comment, parent);
|
|
524
504
|
const lark = await this.lark({ title, content }, comment, parent);
|
|
525
505
|
|
|
526
|
-
if (
|
|
527
|
-
[wechat, qq, telegram, qywxAmWechat, pushplus, discord, lark].every(
|
|
528
|
-
think.isEmpty,
|
|
529
|
-
)
|
|
530
|
-
) {
|
|
506
|
+
if ([wechat, qq, telegram, qywxAmWechat, pushplus, discord, lark].every(think.isEmpty)) {
|
|
531
507
|
mailList.push({ to: AUTHOR, title, content });
|
|
532
508
|
}
|
|
533
509
|
}
|
|
534
510
|
|
|
535
|
-
const disallowList = this.controller.ctx.state.oauthServices.map(
|
|
536
|
-
({ name }) => 'mail.' + name,
|
|
537
|
-
);
|
|
511
|
+
const disallowList = this.controller.ctx.state.oauthServices.map(({ name }) => 'mail.' + name);
|
|
538
512
|
const fakeMail = new RegExp(`@(${disallowList.join('|')})$`, 'i');
|
|
539
513
|
|
|
540
514
|
if (
|
|
@@ -14,12 +14,7 @@ module.exports = class extends think.Service {
|
|
|
14
14
|
//to be implemented
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async add(
|
|
18
|
-
data,
|
|
19
|
-
{
|
|
20
|
-
access: { read = true, write = true } = { read: true, write: true },
|
|
21
|
-
} = {},
|
|
22
|
-
) {
|
|
17
|
+
async add(data, { access: { read = true, write = true } = { read: true, write: true } } = {}) {
|
|
23
18
|
//to be implemented
|
|
24
19
|
}
|
|
25
20
|
|
|
@@ -53,8 +53,7 @@ class Github {
|
|
|
53
53
|
// content api can only get file < 1MB
|
|
54
54
|
async get(filename) {
|
|
55
55
|
const resp = await fetch(
|
|
56
|
-
'https://api.github.com/repos/' +
|
|
57
|
-
path.join(this.repo, 'contents', filename),
|
|
56
|
+
'https://api.github.com/repos/' + path.join(this.repo, 'contents', filename),
|
|
58
57
|
{
|
|
59
58
|
headers: {
|
|
60
59
|
accept: 'application/vnd.github.v3+json',
|
|
@@ -83,9 +82,7 @@ class Github {
|
|
|
83
82
|
// blob api can get file larger than 1MB
|
|
84
83
|
async getLargeFile(filename) {
|
|
85
84
|
const { tree } = await fetch(
|
|
86
|
-
'https://api.github.com/repos/' +
|
|
87
|
-
path.join(this.repo, 'git/trees/HEAD') +
|
|
88
|
-
'?recursive=1',
|
|
85
|
+
'https://api.github.com/repos/' + path.join(this.repo, 'git/trees/HEAD') + '?recursive=1',
|
|
89
86
|
{
|
|
90
87
|
headers: {
|
|
91
88
|
accept: 'application/vnd.github.v3+json',
|
|
@@ -114,23 +111,19 @@ class Github {
|
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
async set(filename, content, { sha }) {
|
|
117
|
-
return fetch(
|
|
118
|
-
'
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
accept: 'application/vnd.github.v3+json',
|
|
124
|
-
authorization: 'token ' + this.token,
|
|
125
|
-
'user-agent': 'Waline',
|
|
126
|
-
},
|
|
127
|
-
body: JSON.stringify({
|
|
128
|
-
sha,
|
|
129
|
-
message: 'feat(waline): update comment data',
|
|
130
|
-
content: Buffer.from(content, 'utf-8').toString('base64'),
|
|
131
|
-
}),
|
|
114
|
+
return fetch('https://api.github.com/repos/' + path.join(this.repo, 'contents', filename), {
|
|
115
|
+
method: 'PUT',
|
|
116
|
+
headers: {
|
|
117
|
+
accept: 'application/vnd.github.v3+json',
|
|
118
|
+
authorization: 'token ' + this.token,
|
|
119
|
+
'user-agent': 'Waline',
|
|
132
120
|
},
|
|
133
|
-
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
sha,
|
|
123
|
+
message: 'feat(waline): update comment data',
|
|
124
|
+
content: Buffer.from(content, 'utf-8').toString('base64'),
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
134
127
|
}
|
|
135
128
|
}
|
|
136
129
|
|
|
@@ -266,9 +259,7 @@ module.exports = class extends Base {
|
|
|
266
259
|
|
|
267
260
|
const logicFn = logicMap[where._complex._logic];
|
|
268
261
|
|
|
269
|
-
return data.filter((item) =>
|
|
270
|
-
logicFn.call(filters, (filter) => filter.every((fn) => fn(item))),
|
|
271
|
-
);
|
|
262
|
+
return data.filter((item) => logicFn.call(filters, (filter) => filter.every((fn) => fn(item))));
|
|
272
263
|
}
|
|
273
264
|
|
|
274
265
|
async select(where, { desc, limit, offset, field } = {}) {
|
|
@@ -185,10 +185,7 @@ module.exports = class extends Base {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
async _updateCmtGroupByMailUserIdCache(data, method) {
|
|
188
|
-
if (
|
|
189
|
-
this.tableName !== 'Comment' ||
|
|
190
|
-
!think.isArray(think.config('levels'))
|
|
191
|
-
) {
|
|
188
|
+
if (this.tableName !== 'Comment' || !think.isArray(think.config('levels'))) {
|
|
192
189
|
return;
|
|
193
190
|
}
|
|
194
191
|
|
|
@@ -200,9 +197,7 @@ module.exports = class extends Base {
|
|
|
200
197
|
const cacheData = await this.select({
|
|
201
198
|
_complex: {
|
|
202
199
|
_logic: 'or',
|
|
203
|
-
user_id: think.isObject(data.user_id)
|
|
204
|
-
? data.user_id.toString()
|
|
205
|
-
: data.user_id,
|
|
200
|
+
user_id: think.isObject(data.user_id) ? data.user_id.toString() : data.user_id,
|
|
206
201
|
mail: data.mail,
|
|
207
202
|
},
|
|
208
203
|
});
|
|
@@ -234,14 +229,12 @@ module.exports = class extends Base {
|
|
|
234
229
|
const currentTableName = this.tableName;
|
|
235
230
|
|
|
236
231
|
this.tableName = cacheTableName;
|
|
237
|
-
await this.update({ count }, { objectId: cacheData[0].objectId }).catch(
|
|
238
|
-
(e)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
);
|
|
232
|
+
await this.update({ count }, { objectId: cacheData[0].objectId }).catch((e) => {
|
|
233
|
+
if (e.code === 101) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
throw e;
|
|
237
|
+
});
|
|
245
238
|
this.tableName = currentTableName;
|
|
246
239
|
}
|
|
247
240
|
|
|
@@ -258,10 +251,7 @@ module.exports = class extends Base {
|
|
|
258
251
|
}
|
|
259
252
|
|
|
260
253
|
// get group count cache by group field where data
|
|
261
|
-
const cacheData = await this._getCmtGroupByMailUserIdCache(
|
|
262
|
-
options.group.join('_'),
|
|
263
|
-
where,
|
|
264
|
-
);
|
|
254
|
+
const cacheData = await this._getCmtGroupByMailUserIdCache(options.group.join('_'), where);
|
|
265
255
|
|
|
266
256
|
if (!where._complex) {
|
|
267
257
|
if (cacheData.length) {
|
|
@@ -272,9 +262,7 @@ module.exports = class extends Base {
|
|
|
272
262
|
const countsMap = {};
|
|
273
263
|
|
|
274
264
|
for (const count of counts) {
|
|
275
|
-
const key = options.group
|
|
276
|
-
.map((item) => count[item] || undefined)
|
|
277
|
-
.join('_');
|
|
265
|
+
const key = options.group.map((item) => count[item] || undefined).join('_');
|
|
278
266
|
|
|
279
267
|
if (!countsMap[key]) {
|
|
280
268
|
countsMap[key] = {};
|
|
@@ -298,9 +286,7 @@ module.exports = class extends Base {
|
|
|
298
286
|
const cacheDataMap = {};
|
|
299
287
|
|
|
300
288
|
for (const item of cacheData) {
|
|
301
|
-
const key = options.group
|
|
302
|
-
.map((item) => item[item] || undefined)
|
|
303
|
-
.join('_');
|
|
289
|
+
const key = options.group.map((item) => item[item] || undefined).join('_');
|
|
304
290
|
|
|
305
291
|
cacheDataMap[key] = item;
|
|
306
292
|
}
|
|
@@ -364,12 +350,7 @@ module.exports = class extends Base {
|
|
|
364
350
|
return [...cacheData, ...counts];
|
|
365
351
|
}
|
|
366
352
|
|
|
367
|
-
async add(
|
|
368
|
-
data,
|
|
369
|
-
{
|
|
370
|
-
access: { read = true, write = true } = { read: true, write: true },
|
|
371
|
-
} = {},
|
|
372
|
-
) {
|
|
353
|
+
async add(data, { access: { read = true, write = true } = { read: true, write: true } } = {}) {
|
|
373
354
|
const Table = AV.Object.extend(this.tableName);
|
|
374
355
|
const instance = new Table();
|
|
375
356
|
|
|
@@ -403,8 +384,7 @@ module.exports = class extends Base {
|
|
|
403
384
|
ret.map(async (item) => {
|
|
404
385
|
const _oldStatus = item.get('status');
|
|
405
386
|
|
|
406
|
-
const updateData =
|
|
407
|
-
typeof data === 'function' ? data(item.toJSON()) : data;
|
|
387
|
+
const updateData = typeof data === 'function' ? data(item.toJSON()) : data;
|
|
408
388
|
|
|
409
389
|
const REVERSED_KEYS = ['createdAt', 'updatedAt'];
|
|
410
390
|
|
|
@@ -40,8 +40,7 @@ module.exports = class extends Base {
|
|
|
40
40
|
break;
|
|
41
41
|
case 'NOT IN':
|
|
42
42
|
filter[parseKey(k)] = {
|
|
43
|
-
$nin:
|
|
44
|
-
k === 'objectId' ? where[k][1].map(ObjectId) : where[k][1],
|
|
43
|
+
$nin: k === 'objectId' ? where[k][1].map(ObjectId) : where[k][1],
|
|
45
44
|
};
|
|
46
45
|
break;
|
|
47
46
|
case 'LIKE': {
|
|
@@ -90,17 +90,13 @@ module.exports = class extends Base {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
async update(data, where) {
|
|
93
|
-
const list = await this.model(this.tableName)
|
|
94
|
-
.where(this.parseWhere(where))
|
|
95
|
-
.select();
|
|
93
|
+
const list = await this.model(this.tableName).where(this.parseWhere(where)).select();
|
|
96
94
|
|
|
97
95
|
return Promise.all(
|
|
98
96
|
list.map(async (item) => {
|
|
99
97
|
const updateData = typeof data === 'function' ? data(item) : data;
|
|
100
98
|
|
|
101
|
-
await this.model(this.tableName)
|
|
102
|
-
.where({ id: item.id })
|
|
103
|
-
.update(updateData);
|
|
99
|
+
await this.model(this.tableName).where({ id: item.id }).update(updateData);
|
|
104
100
|
|
|
105
101
|
return { ...item, ...updateData };
|
|
106
102
|
}),
|
|
@@ -116,8 +112,6 @@ module.exports = class extends Base {
|
|
|
116
112
|
async setSeqId(id) {
|
|
117
113
|
const instance = this.model(this.tableName);
|
|
118
114
|
|
|
119
|
-
return instance.query(
|
|
120
|
-
`ALTER TABLE ${instance.tableName} AUTO_INCREMENT = ${id};`,
|
|
121
|
-
);
|
|
115
|
+
return instance.query(`ALTER TABLE ${instance.tableName} AUTO_INCREMENT = ${id};`);
|
|
122
116
|
}
|
|
123
117
|
};
|
|
@@ -48,9 +48,7 @@ module.exports = class extends MySQL {
|
|
|
48
48
|
const val = data[key];
|
|
49
49
|
|
|
50
50
|
data[key.toLowerCase()] =
|
|
51
|
-
val instanceof Date
|
|
52
|
-
? think.datetime(val, 'YYYY-MM-DD HH:mm:ss')
|
|
53
|
-
: val;
|
|
51
|
+
val instanceof Date ? think.datetime(val, 'YYYY-MM-DD HH:mm:ss') : val;
|
|
54
52
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
55
53
|
delete data[key];
|
|
56
54
|
});
|
|
@@ -79,8 +77,6 @@ module.exports = class extends MySQL {
|
|
|
79
77
|
async setSeqId(id) {
|
|
80
78
|
const instance = this.model(this.tableName);
|
|
81
79
|
|
|
82
|
-
return instance.query(
|
|
83
|
-
`ALTER SEQUENCE ${instance.tableName}_seq RESTART WITH ${id};`,
|
|
84
|
-
);
|
|
80
|
+
return instance.query(`ALTER SEQUENCE ${instance.tableName}_seq RESTART WITH ${id};`);
|
|
85
81
|
}
|
|
86
82
|
};
|