twikoo-vercel 1.7.13 → 1.7.15
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/api/index.js +39 -2
- package/package.json +2 -2
package/api/index.js
CHANGED
|
@@ -42,6 +42,13 @@ const {
|
|
|
42
42
|
checkCommentOwnership,
|
|
43
43
|
isValidEmail
|
|
44
44
|
} = require('twikoo-func/utils')
|
|
45
|
+
const {
|
|
46
|
+
createCap,
|
|
47
|
+
mongoStorage,
|
|
48
|
+
createChallenge,
|
|
49
|
+
redeemChallenge,
|
|
50
|
+
isBuiltinCap
|
|
51
|
+
} = require('twikoo-func/utils/cap')
|
|
45
52
|
const {
|
|
46
53
|
jsonParse,
|
|
47
54
|
commentImportValine,
|
|
@@ -157,6 +164,12 @@ module.exports = async (request, response) => {
|
|
|
157
164
|
case 'COMMENT_EXPORT_FOR_ADMIN': // >= 1.6.13
|
|
158
165
|
res = await commentExportForAdmin(event)
|
|
159
166
|
break
|
|
167
|
+
case 'CAP_CHALLENGE':
|
|
168
|
+
res = await capChallenge()
|
|
169
|
+
break
|
|
170
|
+
case 'CAP_REDEEM':
|
|
171
|
+
res = await capRedeem(event)
|
|
172
|
+
break
|
|
160
173
|
default:
|
|
161
174
|
if (event.event) {
|
|
162
175
|
res.code = RES_CODE.EVENT_NOT_EXIST
|
|
@@ -796,6 +809,14 @@ async function checkCaptcha (comment, request) {
|
|
|
796
809
|
geeTestPassToken: comment.geeTestPassToken,
|
|
797
810
|
geeTestGenTime: comment.geeTestGenTime
|
|
798
811
|
})
|
|
812
|
+
} else if (provider === 'Cap' && isBuiltinCap(config)) {
|
|
813
|
+
if (!comment.capToken) {
|
|
814
|
+
throw new Error('验证码 token 缺失,请刷新页面重试')
|
|
815
|
+
}
|
|
816
|
+
await checkCapCaptcha({
|
|
817
|
+
capToken: comment.capToken,
|
|
818
|
+
cap: createCap(mongoStorage(db))
|
|
819
|
+
})
|
|
799
820
|
} else if (provider === 'Cap' && config.CAP_API_ENDPOINT && config.CAP_SECRET_KEY) {
|
|
800
821
|
if (!comment.capToken) {
|
|
801
822
|
throw new Error('验证码 token 缺失,请刷新页面重试')
|
|
@@ -806,7 +827,7 @@ async function checkCaptcha (comment, request) {
|
|
|
806
827
|
capApiEndpoint: config.CAP_API_ENDPOINT
|
|
807
828
|
})
|
|
808
829
|
} else if (provider === 'Cap') {
|
|
809
|
-
throw new Error('Cap
|
|
830
|
+
throw new Error('Cap 验证码配置不完整:内嵌模式无需额外配置,外部模式需填写 CAP_API_ENDPOINT 与 CAP_SECRET_KEY')
|
|
810
831
|
} else if (provider) {
|
|
811
832
|
throw new Error(`不支持的验证码类型: ${provider}`)
|
|
812
833
|
}
|
|
@@ -1061,7 +1082,7 @@ function isRecursion (request) {
|
|
|
1061
1082
|
|
|
1062
1083
|
// 建立数据库 collections
|
|
1063
1084
|
async function createCollections () {
|
|
1064
|
-
const collections = ['comment', 'config', 'counter']
|
|
1085
|
+
const collections = ['comment', 'config', 'counter', 'cap_challenges', 'cap_tokens']
|
|
1065
1086
|
const res = {}
|
|
1066
1087
|
for (const collection of collections) {
|
|
1067
1088
|
try {
|
|
@@ -1073,6 +1094,22 @@ async function createCollections () {
|
|
|
1073
1094
|
return res
|
|
1074
1095
|
}
|
|
1075
1096
|
|
|
1097
|
+
async function capChallenge () {
|
|
1098
|
+
if (!isBuiltinCap(config)) {
|
|
1099
|
+
return { code: RES_CODE.FAIL, message: '内嵌 Cap 未启用' }
|
|
1100
|
+
}
|
|
1101
|
+
const data = await createChallenge(createCap(mongoStorage(db)))
|
|
1102
|
+
return { code: RES_CODE.SUCCESS, ...data }
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
async function capRedeem (event) {
|
|
1106
|
+
if (!isBuiltinCap(config)) {
|
|
1107
|
+
return { code: RES_CODE.FAIL, message: '内嵌 Cap 未启用' }
|
|
1108
|
+
}
|
|
1109
|
+
const data = await redeemChallenge(createCap(mongoStorage(db)), event)
|
|
1110
|
+
return { code: RES_CODE.SUCCESS, ...data }
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1076
1113
|
function getIp (request) {
|
|
1077
1114
|
try {
|
|
1078
1115
|
const { TWIKOO_IP_HEADERS } = process.env
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twikoo-vercel",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.15",
|
|
4
4
|
"description": "A simple comment system.",
|
|
5
5
|
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"get-user-ip": "^1.0.1",
|
|
15
15
|
"mongodb": "^6.3.0",
|
|
16
|
-
"twikoo-func": "1.7.
|
|
16
|
+
"twikoo-func": "1.7.15",
|
|
17
17
|
"uuid": "^8.3.2"
|
|
18
18
|
}
|
|
19
19
|
}
|