twikoo-func 1.7.4 → 1.7.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/index.js CHANGED
@@ -31,6 +31,7 @@ const {
31
31
  preCheckSpam,
32
32
  checkTurnstileCaptcha,
33
33
  checkGeeTestCaptcha,
34
+ checkCapCaptcha,
34
35
  getConfig,
35
36
  getConfigForAdmin,
36
37
  validate
@@ -719,13 +720,13 @@ async function limitFilter () {
719
720
 
720
721
  async function checkCaptcha (comment) {
721
722
  const provider = config.CAPTCHA_PROVIDER
722
- if ((!provider || provider === 'Turnstile') && config.TURNSTILE_SITE_KEY && config.TURNSTILE_SECRET_KEY) {
723
+ if (provider === 'Turnstile' && config.TURNSTILE_SITE_KEY && config.TURNSTILE_SECRET_KEY) {
723
724
  await checkTurnstileCaptcha({
724
725
  ip: auth.getClientIP(),
725
726
  turnstileToken: comment.turnstileToken,
726
727
  turnstileTokenSecretKey: config.TURNSTILE_SECRET_KEY
727
728
  })
728
- } else if ((!provider || provider === 'Geetest') && config.GEETEST_CAPTCHA_ID && config.GEETEST_CAPTCHA_KEY) {
729
+ } else if (provider === 'Geetest' && config.GEETEST_CAPTCHA_ID && config.GEETEST_CAPTCHA_KEY) {
729
730
  await checkGeeTestCaptcha({
730
731
  geeTestCaptchaId: config.GEETEST_CAPTCHA_ID,
731
732
  geeTestCaptchaKey: config.GEETEST_CAPTCHA_KEY,
@@ -734,6 +735,12 @@ async function checkCaptcha (comment) {
734
735
  geeTestPassToken: comment.geeTestPassToken,
735
736
  geeTestGenTime: comment.geeTestGenTime
736
737
  })
738
+ } else if (provider === 'Cap' && config.CAP_API_ENDPOINT && config.CAP_SECRET_KEY) {
739
+ await checkCapCaptcha({
740
+ capToken: comment.capToken,
741
+ capSecretKey: config.CAP_SECRET_KEY,
742
+ capApiEndpoint: config.CAP_API_ENDPOINT
743
+ })
737
744
  }
738
745
  }
739
746
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twikoo-func",
3
- "version": "1.7.4",
3
+ "version": "1.7.5",
4
4
  "description": "A simple comment system.",
5
5
  "author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
6
6
  "license": "MIT",
package/utils/image.js CHANGED
@@ -12,7 +12,7 @@ const fn = {
12
12
  async uploadImage (event, config) {
13
13
  const { photo, fileName } = event
14
14
  const res = {}
15
- const imageService = config.IMAGE_SERVICE || config.IMAGE_CDN
15
+ const imageService = config.IMAGE_CDN
16
16
  try {
17
17
  if (imageService === 's3') {
18
18
  // S3 图床只需要配置相关 S3 参数,不需要 IMAGE_CDN_TOKEN
package/utils/index.js CHANGED
@@ -354,6 +354,21 @@ const fn = {
354
354
  throw new Error('极验验证码检测失败: ' + e.message)
355
355
  }
356
356
  },
357
+ async checkCapCaptcha ({ capToken, capSecretKey, capApiEndpoint }) {
358
+ try {
359
+ const params = new URLSearchParams()
360
+ params.append('response', capToken)
361
+ params.append('secret', capSecretKey)
362
+ const url = `${capApiEndpoint}/siteverify`
363
+ const { data } = await axios.post(url, params.toString(), {
364
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
365
+ })
366
+ logger.log('Cap验证码检测结果', data)
367
+ if (!data.success) throw new Error(data.error || '验证码错误')
368
+ } catch (e) {
369
+ throw new Error('Cap验证码检测失败: ' + e.message)
370
+ }
371
+ },
357
372
  async getConfig ({ config, VERSION, isAdmin }) {
358
373
  // 构建对外配置,避免在启用某一验证码供应商时泄露另一个供应商的 key
359
374
  const baseConfig = {
@@ -367,7 +382,6 @@ const fn = {
367
382
  DEFAULT_GRAVATAR: config.DEFAULT_GRAVATAR,
368
383
  SHOW_IMAGE: config.SHOW_IMAGE || 'true',
369
384
  IMAGE_CDN: config.IMAGE_CDN,
370
- IMAGE_SERVICE: config.IMAGE_SERVICE,
371
385
  LIGHTBOX: config.LIGHTBOX || 'false',
372
386
  SHOW_EMOTION: config.SHOW_EMOTION || 'true',
373
387
  EMOTION_CDN: config.EMOTION_CDN,
@@ -395,6 +409,12 @@ const fn = {
395
409
  baseConfig.GEETEST_CAPTCHA_ID = config.GEETEST_CAPTCHA_ID
396
410
  }
397
411
 
412
+ // 仅在明确指定使用 Cap 时下发 Cap 的 api endpoint 和 site key
413
+ if (config.CAPTCHA_PROVIDER === 'Cap') {
414
+ baseConfig.CAP_API_ENDPOINT = config.CAP_API_ENDPOINT
415
+ baseConfig.CAP_SITE_KEY = config.CAP_SITE_KEY
416
+ }
417
+
398
418
  return {
399
419
  code: RES_CODE.SUCCESS,
400
420
  config: baseConfig