@waline/vercel 1.17.4 → 1.18.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 +1 -1
- package/src/controller/comment.js +19 -2
- package/src/logic/comment.js +16 -4
package/package.json
CHANGED
|
@@ -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
|
|
|
@@ -568,13 +571,27 @@ module.exports = class extends BaseRest {
|
|
|
568
571
|
}
|
|
569
572
|
|
|
570
573
|
async putAction() {
|
|
571
|
-
const
|
|
574
|
+
const { userInfo } = this.ctx.state;
|
|
575
|
+
let data = this.post();
|
|
572
576
|
let oldData = await this.modelInstance.select({ objectId: this.id });
|
|
573
577
|
if (think.isEmpty(oldData)) {
|
|
574
578
|
return this.success();
|
|
575
579
|
}
|
|
576
580
|
|
|
577
581
|
oldData = oldData[0];
|
|
582
|
+
if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
|
|
583
|
+
if (!think.isBoolean(data.like)) {
|
|
584
|
+
return this.success();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const likeIncMax = this.config('LIKE_INC_MAX') || 1;
|
|
588
|
+
data = {
|
|
589
|
+
like:
|
|
590
|
+
(Number(oldData.like) || 0) +
|
|
591
|
+
(data.like ? Math.ceil(Math.random() * likeIncMax) : -1),
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
578
595
|
const preUpdateResp = await this.hook('preUpdate', {
|
|
579
596
|
...data,
|
|
580
597
|
objectId: this.id,
|
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
|