@midwayjs/captcha 3.7.3 → 3.7.4

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.
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.captcha = void 0;
4
4
  exports.captcha = {
5
- size: 4,
6
- noise: 1,
7
- width: 120,
8
- height: 40,
5
+ default: {
6
+ size: 4,
7
+ noise: 1,
8
+ width: 120,
9
+ height: 40,
10
+ },
9
11
  image: {
10
12
  type: 'mixed',
11
13
  },
@@ -5,6 +5,7 @@ interface BaseCaptchaOptions {
5
5
  height?: number;
6
6
  }
7
7
  export interface CaptchaOptions extends BaseCaptchaOptions {
8
+ default?: BaseCaptchaOptions;
8
9
  image?: ImageCaptchaOptions;
9
10
  formula?: FormulaCaptchaOptions;
10
11
  text?: TextCaptchaOptions;
package/dist/service.js CHANGED
@@ -18,7 +18,7 @@ const nanoid_1 = require("nanoid");
18
18
  const constants_1 = require("./constants");
19
19
  let CaptchaService = class CaptchaService {
20
20
  async image(options) {
21
- const { width, height, type } = Object.assign({}, this.captcha, this.captcha.image, options);
21
+ const { width, height, type, size, noise } = Object.assign({}, this.captcha, this.captcha.default, this.captcha.image, options);
22
22
  let ignoreChars = '';
23
23
  switch (type) {
24
24
  case 'letter':
@@ -32,23 +32,26 @@ let CaptchaService = class CaptchaService {
32
32
  ignoreChars,
33
33
  width,
34
34
  height,
35
+ size,
36
+ noise,
35
37
  });
36
38
  const id = await this.set(text);
37
39
  const imageBase64 = svgBase64(data);
38
40
  return { id, imageBase64 };
39
41
  }
40
42
  async formula(options) {
41
- const { width, height } = Object.assign({}, this.captcha, this.captcha.formula, options);
43
+ const { width, height, noise } = Object.assign({}, this.captcha, this.captcha.default, this.captcha.formula, options);
42
44
  const { data, text } = svgCaptcha.createMathExpr({
43
45
  width,
44
46
  height,
47
+ noise,
45
48
  });
46
49
  const id = await this.set(text);
47
50
  const imageBase64 = svgBase64(data);
48
51
  return { id, imageBase64 };
49
52
  }
50
53
  async text(options) {
51
- const textOptions = Object.assign({}, this.captcha, this.captcha.text, options);
54
+ const textOptions = Object.assign({}, this.captcha, this.captcha.default, this.captcha.text, options);
52
55
  let chars = '';
53
56
  switch (textOptions.type) {
54
57
  case 'letter':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/captcha",
3
- "version": "3.7.3",
3
+ "version": "3.7.4",
4
4
  "description": "Midway Component for Captcha(Verification Code)",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -32,5 +32,5 @@
32
32
  "@midwayjs/koa": "^3.7.3",
33
33
  "@midwayjs/mock": "^3.7.3"
34
34
  },
35
- "gitHead": "8e6c830bca52818e0086873b542423d16e609aef"
35
+ "gitHead": "bb659c7f553ee61832b87eb4c16b024749897636"
36
36
  }