@waline/vercel 1.17.3 → 1.18.1
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/.eslintrc.yml +7 -0
- package/__tests__/__snapshots__/xss.spec.js.snap +2 -2
- package/__tests__/katex.spec.js +6 -4
- package/__tests__/mathjax.spec.js +3 -2
- package/__tests__/xss.spec.js +4 -2
- package/index.js +2 -2
- package/package.json +4 -1
- package/src/config/config.js +1 -1
- package/src/controller/comment.js +28 -4
- package/src/controller/db.js +2 -2
- package/src/controller/oauth.js +1 -1
- package/src/controller/rest.js +1 -1
- package/src/controller/user.js +1 -1
- package/src/logic/comment.js +16 -4
- package/src/service/storage/github.js +1 -1
- package/src/service/storage/leancloud.js +14 -3
- package/vanilla.js +1 -1
package/.eslintrc.yml
CHANGED
package/__tests__/katex.spec.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import MarkdownIt from 'markdown-it';
|
|
3
|
+
import { katexPlugin } from '../src/service/markdown/katex';
|
|
4
|
+
import { vi } from 'vitest';
|
|
3
5
|
|
|
4
6
|
const markdownIt = MarkdownIt({ linkify: true }).use(katexPlugin, {
|
|
5
7
|
output: 'mathml',
|
|
@@ -46,7 +48,7 @@ describe('inline katex', () => {
|
|
|
46
48
|
it('Should render error msg when content is wrong', () => {
|
|
47
49
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
48
50
|
const originalWarn = global.console.warn;
|
|
49
|
-
global.console.warn =
|
|
51
|
+
global.console.warn = vi.fn();
|
|
50
52
|
|
|
51
53
|
expect(markdownItWithError.render('$\\fra{a}{b}$')).toEqual(
|
|
52
54
|
"<p><span class='katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \\fra at position 1: \\̲f̲r̲a̲{a}{b}'>\\fra{a}{b}</span></p>\n"
|
|
@@ -117,7 +119,7 @@ $$
|
|
|
117
119
|
it('Should render error msg when content is wrong', () => {
|
|
118
120
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
119
121
|
const originalWarn = global.console.warn;
|
|
120
|
-
global.console.warn =
|
|
122
|
+
global.console.warn = vi.fn();
|
|
121
123
|
expect(markdownItWithError.render('$$\\fra{a}{b}$$')).toMatch(
|
|
122
124
|
/<p class='katex-block katex-error' title='[\s\S]*?'>[\s\S]*?<\/p>/
|
|
123
125
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import MarkdownIt from 'markdown-it';
|
|
3
|
+
import { mathjaxPlugin } from '../src/service/markdown/mathjax';
|
|
3
4
|
|
|
4
5
|
const markdownIt = MarkdownIt({ linkify: true }).use(mathjaxPlugin);
|
|
5
6
|
|
package/__tests__/xss.spec.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import MarkdownIt from 'markdown-it';
|
|
3
|
+
import { sanitize } from '../src/service/markdown/xss';
|
|
4
|
+
|
|
3
5
|
const parser = (content) =>
|
|
4
6
|
sanitize(new MarkdownIt({ html: true }).render(content));
|
|
5
7
|
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/vercel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "vercel server for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"waline",
|
|
@@ -47,5 +47,8 @@
|
|
|
47
47
|
"think-router-rest": "^1.0.5",
|
|
48
48
|
"thinkjs": "^3.2.14",
|
|
49
49
|
"ua-parser-js": "^1.0.2"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=14"
|
|
50
53
|
}
|
|
51
54
|
}
|
package/src/config/config.js
CHANGED
|
@@ -92,7 +92,7 @@ const markdown = {
|
|
|
92
92
|
|
|
93
93
|
if (isFalse(MARKDOWN_HIGHLIGHT)) markdown.config.highlight = false;
|
|
94
94
|
|
|
95
|
-
let avatarProxy = '
|
|
95
|
+
let avatarProxy = '';
|
|
96
96
|
if (AVATAR_PROXY) {
|
|
97
97
|
avatarProxy = !isFalse(AVATAR_PROXY) ? AVATAR_PROXY : '';
|
|
98
98
|
}
|
|
@@ -50,6 +50,7 @@ async function formatCmt(
|
|
|
50
50
|
comment.addr = await think.ip2region(ip, { depth: isAdmin ? 3 : 1 });
|
|
51
51
|
}
|
|
52
52
|
comment.comment = markdownParser(comment.comment);
|
|
53
|
+
comment.like = Number(comment.like) || 0;
|
|
53
54
|
return comment;
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -97,6 +98,7 @@ module.exports = class extends BaseRest {
|
|
|
97
98
|
'ip',
|
|
98
99
|
'user_id',
|
|
99
100
|
'sticky',
|
|
101
|
+
'like',
|
|
100
102
|
],
|
|
101
103
|
});
|
|
102
104
|
|
|
@@ -231,7 +233,7 @@ module.exports = class extends BaseRest {
|
|
|
231
233
|
const where = { url };
|
|
232
234
|
if (think.isEmpty(userInfo) || this.config('storage') === 'deta') {
|
|
233
235
|
where.status = ['NOT IN', ['waiting', 'spam']];
|
|
234
|
-
} else {
|
|
236
|
+
} else if (userInfo.type !== 'administrator') {
|
|
235
237
|
where._complex = {
|
|
236
238
|
_logic: 'or',
|
|
237
239
|
status: ['NOT IN', ['waiting', 'spam']],
|
|
@@ -259,6 +261,7 @@ module.exports = class extends BaseRest {
|
|
|
259
261
|
'ip',
|
|
260
262
|
'user_id',
|
|
261
263
|
'sticky',
|
|
264
|
+
'like',
|
|
262
265
|
],
|
|
263
266
|
};
|
|
264
267
|
|
|
@@ -553,7 +556,10 @@ module.exports = class extends BaseRest {
|
|
|
553
556
|
|
|
554
557
|
if (comment.status !== 'spam') {
|
|
555
558
|
const notify = this.service('notify');
|
|
556
|
-
await notify.run(
|
|
559
|
+
await notify.run(
|
|
560
|
+
{ ...resp, comment: markdownParser(resp.comment), rawComment: comment },
|
|
561
|
+
{ ...parentComment, comment: markdownParser(parentComment.comment) }
|
|
562
|
+
);
|
|
557
563
|
}
|
|
558
564
|
|
|
559
565
|
think.logger.debug(`Comment notify done!`);
|
|
@@ -568,13 +574,27 @@ module.exports = class extends BaseRest {
|
|
|
568
574
|
}
|
|
569
575
|
|
|
570
576
|
async putAction() {
|
|
571
|
-
const
|
|
577
|
+
const { userInfo } = this.ctx.state;
|
|
578
|
+
let data = this.post();
|
|
572
579
|
let oldData = await this.modelInstance.select({ objectId: this.id });
|
|
573
580
|
if (think.isEmpty(oldData)) {
|
|
574
581
|
return this.success();
|
|
575
582
|
}
|
|
576
583
|
|
|
577
584
|
oldData = oldData[0];
|
|
585
|
+
if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
|
|
586
|
+
if (!think.isBoolean(data.like)) {
|
|
587
|
+
return this.success();
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const likeIncMax = this.config('LIKE_INC_MAX') || 1;
|
|
591
|
+
data = {
|
|
592
|
+
like:
|
|
593
|
+
(Number(oldData.like) || 0) +
|
|
594
|
+
(data.like ? Math.ceil(Math.random() * likeIncMax) : -1),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
578
598
|
const preUpdateResp = await this.hook('preUpdate', {
|
|
579
599
|
...data,
|
|
580
600
|
objectId: this.id,
|
|
@@ -599,7 +619,11 @@ module.exports = class extends BaseRest {
|
|
|
599
619
|
pComment = pComment[0];
|
|
600
620
|
|
|
601
621
|
const notify = this.service('notify');
|
|
602
|
-
await notify.run(
|
|
622
|
+
await notify.run(
|
|
623
|
+
{ ...newData, comment: markdownParser(newData.comment) },
|
|
624
|
+
{ ...pComment, comment: markdownParser(pComment.comment) },
|
|
625
|
+
true
|
|
626
|
+
);
|
|
603
627
|
}
|
|
604
628
|
|
|
605
629
|
await this.hook('postUpdate', data);
|
package/src/controller/db.js
CHANGED
package/src/controller/oauth.js
CHANGED
package/src/controller/rest.js
CHANGED
package/src/controller/user.js
CHANGED
package/src/logic/comment.js
CHANGED
|
@@ -4,9 +4,10 @@ module.exports = class extends Base {
|
|
|
4
4
|
await super.__before();
|
|
5
5
|
|
|
6
6
|
const { type, path } = this.get();
|
|
7
|
+
const { like } = this.post();
|
|
7
8
|
const isAllowedGet = this.isGet && (type !== 'list' || path);
|
|
8
|
-
|
|
9
|
-
if (this.isPost || isAllowedGet) {
|
|
9
|
+
const isAllowedPut = this.ctx.isMethod('PUT') && think.isBoolean(like);
|
|
10
|
+
if (this.isPost || isAllowedGet || isAllowedPut) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -207,7 +208,7 @@ module.exports = class extends Base {
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
/**
|
|
210
|
-
* @api {
|
|
211
|
+
* @api {PUT} /comment/:id update comment data
|
|
211
212
|
* @apiGroup Comment
|
|
212
213
|
* @apiVersion 0.0.1
|
|
213
214
|
*
|
|
@@ -216,11 +217,22 @@ module.exports = class extends Base {
|
|
|
216
217
|
* @apiParam {String} [link] post comment user link
|
|
217
218
|
* @apiParam {String} [comment] post comment text
|
|
218
219
|
* @apiParam {String} [url] the artcile url path of comment
|
|
220
|
+
* @apiParam {Boolean} [like] like comment
|
|
219
221
|
*
|
|
220
222
|
* @apiSuccess (200) {Number} errno 0
|
|
221
223
|
* @apiSuccess (200) {String} errmsg return error message if error
|
|
222
224
|
*/
|
|
223
|
-
putAction() {
|
|
225
|
+
putAction() {
|
|
226
|
+
const { userInfo } = this.ctx.state;
|
|
227
|
+
if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
|
|
228
|
+
this.rules = {
|
|
229
|
+
like: {
|
|
230
|
+
required: true,
|
|
231
|
+
boolean: true,
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
224
236
|
|
|
225
237
|
/**
|
|
226
238
|
* @api {DELETE} /comment/:id delete comment
|
|
@@ -127,7 +127,11 @@ module.exports = class extends Base {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
async _getCmtGroupByMailUserIdCache(key, where) {
|
|
130
|
-
if (
|
|
130
|
+
if (
|
|
131
|
+
this.tableName !== 'Comment' ||
|
|
132
|
+
key !== 'user_id_mail' ||
|
|
133
|
+
!think.isArray(think.config('levels'))
|
|
134
|
+
) {
|
|
131
135
|
return [];
|
|
132
136
|
}
|
|
133
137
|
|
|
@@ -140,7 +144,11 @@ module.exports = class extends Base {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
async _setCmtGroupByMailUserIdCache(key, data) {
|
|
143
|
-
if (
|
|
147
|
+
if (
|
|
148
|
+
this.tableName !== 'Comment' ||
|
|
149
|
+
key !== 'user_id_mail' ||
|
|
150
|
+
!think.isArray(think.config('levels'))
|
|
151
|
+
) {
|
|
144
152
|
return;
|
|
145
153
|
}
|
|
146
154
|
|
|
@@ -161,7 +169,10 @@ module.exports = class extends Base {
|
|
|
161
169
|
}
|
|
162
170
|
|
|
163
171
|
async _updateCmtGroupByMailUserIdCache(data, method) {
|
|
164
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
this.tableName !== 'Comment' ||
|
|
174
|
+
!think.isArray(think.config('levels'))
|
|
175
|
+
) {
|
|
165
176
|
return;
|
|
166
177
|
}
|
|
167
178
|
|
package/vanilla.js
CHANGED