tkserver 1.7.22 → 1.7.24
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/index.js +8 -5
- package/mongo.js +8 -5
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const {
|
|
|
40
40
|
getConfig,
|
|
41
41
|
getConfigForAdmin,
|
|
42
42
|
validate,
|
|
43
|
+
validateClientFields,
|
|
43
44
|
checkCommentOwnership,
|
|
44
45
|
isValidEmail
|
|
45
46
|
} = require('twikoo-func/utils')
|
|
@@ -91,6 +92,8 @@ module.exports = async (request, response) => {
|
|
|
91
92
|
let res = {}
|
|
92
93
|
try {
|
|
93
94
|
protect(request)
|
|
95
|
+
// 统一校验客户端字段类型,防止查询操作符对象注入数据库查询条件
|
|
96
|
+
validateClientFields(event)
|
|
94
97
|
// 判断客户端是否自带 accessToken,须在 anonymousSignIn 回填身份之前
|
|
95
98
|
hasClientToken = !!(request.body && request.body.accessToken)
|
|
96
99
|
accessToken = anonymousSignIn(request)
|
|
@@ -334,7 +337,7 @@ async function commentGet (event) {
|
|
|
334
337
|
url: { $in: getUrlQuery(event.url) },
|
|
335
338
|
rid: { $exists: false }
|
|
336
339
|
}
|
|
337
|
-
//
|
|
340
|
+
// 按当前用户和配置查询可见评论
|
|
338
341
|
query = getCommentQuery({ condition, uid, isAdminUser })
|
|
339
342
|
// 读取总条数
|
|
340
343
|
const count = db
|
|
@@ -374,10 +377,7 @@ async function commentGet (event) {
|
|
|
374
377
|
let top = []
|
|
375
378
|
if (!config.TOP_DISABLED && !event.before) {
|
|
376
379
|
// 查询置顶评论
|
|
377
|
-
query = {
|
|
378
|
-
...condition,
|
|
379
|
-
top: true
|
|
380
|
-
}
|
|
380
|
+
query = getCommentQuery({ condition: { ...condition, top: true }, uid, isAdminUser })
|
|
381
381
|
top = db
|
|
382
382
|
.getCollection('comment')
|
|
383
383
|
.chain()
|
|
@@ -467,6 +467,9 @@ async function commentSearch (event) {
|
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
function getCommentQuery ({ condition, uid, isAdminUser }) {
|
|
470
|
+
if (config.HIDE_SPAM === 'true') {
|
|
471
|
+
return { ...condition, isSpam: { $ne: true } }
|
|
472
|
+
}
|
|
470
473
|
return {
|
|
471
474
|
$or: [
|
|
472
475
|
{ ...condition, isSpam: { $ne: isAdminUser ? 'imaegoo' : true } },
|
package/mongo.js
CHANGED
|
@@ -37,6 +37,7 @@ const {
|
|
|
37
37
|
getConfig,
|
|
38
38
|
getConfigForAdmin,
|
|
39
39
|
validate,
|
|
40
|
+
validateClientFields,
|
|
40
41
|
checkCommentOwnership
|
|
41
42
|
} = require('twikoo-func/utils')
|
|
42
43
|
const {
|
|
@@ -86,6 +87,8 @@ module.exports = async (request, response) => {
|
|
|
86
87
|
let res = {}
|
|
87
88
|
try {
|
|
88
89
|
protect(request)
|
|
90
|
+
// 统一校验客户端字段类型,防止查询操作符对象注入数据库查询条件
|
|
91
|
+
validateClientFields(event)
|
|
89
92
|
// 判断客户端是否自带 accessToken,须在 anonymousSignIn 回填身份之前
|
|
90
93
|
hasClientToken = !!(request.body && request.body.accessToken)
|
|
91
94
|
accessToken = anonymousSignIn(request)
|
|
@@ -324,7 +327,7 @@ async function commentGet (event) {
|
|
|
324
327
|
url: { $in: getUrlQuery(event.url) },
|
|
325
328
|
rid: { $in: ['', null] }
|
|
326
329
|
}
|
|
327
|
-
//
|
|
330
|
+
// 按当前用户和配置查询可见评论
|
|
328
331
|
query = getCommentQuery({ condition, uid, isAdminUser })
|
|
329
332
|
// 读取总条数
|
|
330
333
|
const count = await db
|
|
@@ -364,10 +367,7 @@ async function commentGet (event) {
|
|
|
364
367
|
let top = []
|
|
365
368
|
if (!config.TOP_DISABLED && !event.before) {
|
|
366
369
|
// 查询置顶评论
|
|
367
|
-
query = {
|
|
368
|
-
...condition,
|
|
369
|
-
top: true
|
|
370
|
-
}
|
|
370
|
+
query = getCommentQuery({ condition: { ...condition, top: true }, uid, isAdminUser })
|
|
371
371
|
top = await db
|
|
372
372
|
.collection('comment')
|
|
373
373
|
.find(query)
|
|
@@ -455,6 +455,9 @@ async function commentSearch (event) {
|
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
function getCommentQuery ({ condition, uid, isAdminUser }) {
|
|
458
|
+
if (config.HIDE_SPAM === 'true') {
|
|
459
|
+
return { ...condition, isSpam: { $ne: true } }
|
|
460
|
+
}
|
|
458
461
|
return {
|
|
459
462
|
$or: [
|
|
460
463
|
{ ...condition, isSpam: { $ne: isAdminUser ? 'imaegoo' : true } },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tkserver",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.24",
|
|
4
4
|
"description": "A simple comment system.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"twikoo",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"get-user-ip": "^1.0.1",
|
|
32
32
|
"lokijs": "^1.5.12",
|
|
33
33
|
"mongodb": "^6.3.0",
|
|
34
|
-
"twikoo-func": "1.7.
|
|
34
|
+
"twikoo-func": "1.7.24",
|
|
35
35
|
"uuid": "^8.3.2"
|
|
36
36
|
}
|
|
37
37
|
}
|