vona-module-a-captcha 5.0.7 → 5.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +32 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import { Middleware } from 'vona-module-a-aspect';
3
3
  import { getRandomInt } from '@cabloy/utils';
4
4
  import { Bean, Scope } from 'vona-module-a-bean';
5
5
  import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
6
- import { Api, Arg } from 'vona-module-a-openapi';
7
- import { Dto, Controller, Web } from 'vona-module-a-web';
6
+ import { Api } from 'vona-module-a-openapi';
7
+ import { Dto, Controller, Web, Arg } from 'vona-module-a-web';
8
8
  import { Passport } from 'vona-module-a-user';
9
9
  import z from 'zod';
10
10
 
@@ -78,10 +78,37 @@ let BeanCaptcha = (_dec$5 = Bean(), _dec2$5 = BeanInfo({
78
78
  return result;
79
79
  }
80
80
  async refresh(id, sceneName) {
81
- // delete cache
82
- await this.scope.cacheRedis.captcha.del(id);
81
+ let captchaData = await this.getCaptchaData(id);
82
+ if (!captchaData) {
83
+ // create
84
+ return await this.create(sceneName);
85
+ }
86
+ // scene
87
+ if (captchaData.scene !== sceneName) this.app.throw(403);
83
88
  // create
84
- return await this.create(sceneName);
89
+ const beanInstance = this._getProviderInstance(captchaData.provider);
90
+ const providerOptions = this._getProviderOptions(captchaData.scene, captchaData.provider);
91
+ const captcha = await beanInstance.create(providerOptions);
92
+ // data
93
+ captchaData = {
94
+ scene: sceneName,
95
+ provider: captchaData.provider,
96
+ token: captcha.token
97
+ };
98
+ // cache
99
+ await this.scope.cacheRedis.captcha.set(captchaData, id, {
100
+ ttl: providerOptions.ttl ?? this.scope.config.captchaProvider.ttl
101
+ });
102
+ // result
103
+ const result = {
104
+ id,
105
+ provider: captchaData.provider,
106
+ payload: captcha.payload
107
+ };
108
+ if (this.scope.config.captcha.showToken) {
109
+ result.token = captcha.token;
110
+ }
111
+ return result;
85
112
  }
86
113
  async verify(id, token, sceneName) {
87
114
  const captchaData = await this.getCaptchaData(id);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-captcha",
3
3
  "type": "module",
4
- "version": "5.0.7",
4
+ "version": "5.0.9",
5
5
  "title": "a-captcha",
6
6
  "vonaModule": {
7
7
  "dependencies": {},