@jayfong/x-server 1.33.11 → 1.34.1

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.
@@ -16,7 +16,12 @@ function defineTask(options) {
16
16
  maxRetriesPerRequest: null,
17
17
  enableReadyCheck: false
18
18
  },
19
- prefix: `${_x.x.appId}_task`
19
+ prefix: `${_x.x.appId}_task`,
20
+ defaultJobOptions: {
21
+ // 都设为 true 防止占用内存
22
+ removeOnComplete: true,
23
+ removeOnFail: true
24
+ }
20
25
  });
21
26
  queue.process(options.concurrency || 1, async job => {
22
27
  return options.handle(job.data);
@@ -38,13 +38,20 @@ class SensitiveWordsService {
38
38
  */
39
39
 
40
40
 
41
- async validate(text) {
41
+ async validate(text, every) {
42
42
  if (!this.mint) {
43
43
  this.mint = new _mintFilter.default(this.options.words);
44
44
  }
45
45
 
46
- const res = this.mint.validator(text);
47
- return res;
46
+ const res = await this.mint.filter(text, {
47
+ replace: false,
48
+ every: !!every,
49
+ words: true
50
+ });
51
+ return {
52
+ pass: !!res.pass,
53
+ words: res.words
54
+ };
48
55
  }
49
56
 
50
57
  }
@@ -7,7 +7,12 @@ export function defineTask(options) {
7
7
  maxRetriesPerRequest: null,
8
8
  enableReadyCheck: false
9
9
  },
10
- prefix: `${x.appId}_task`
10
+ prefix: `${x.appId}_task`,
11
+ defaultJobOptions: {
12
+ // 都设为 true 防止占用内存
13
+ removeOnComplete: true,
14
+ removeOnFail: true
15
+ }
11
16
  });
12
17
  queue.process(options.concurrency || 1, async job => {
13
18
  return options.handle(job.data);
@@ -18,7 +18,10 @@ export declare class SensitiveWordsService implements BaseService {
18
18
  /**
19
19
  * 验证文本是否包含敏感词。
20
20
  */
21
- validate(text: string): Promise<boolean>;
21
+ validate(text: string, every?: boolean): Promise<{
22
+ pass: boolean;
23
+ words: string[];
24
+ }>;
22
25
  }
23
26
  declare module '../x' {
24
27
  interface X {
@@ -31,13 +31,20 @@ export class SensitiveWordsService {
31
31
  */
32
32
 
33
33
 
34
- async validate(text) {
34
+ async validate(text, every) {
35
35
  if (!this.mint) {
36
36
  this.mint = new Mint(this.options.words);
37
37
  }
38
38
 
39
- const res = this.mint.validator(text);
40
- return res;
39
+ const res = await this.mint.filter(text, {
40
+ replace: false,
41
+ every: !!every,
42
+ words: true
43
+ });
44
+ return {
45
+ pass: !!res.pass,
46
+ words: res.words
47
+ };
41
48
  }
42
49
 
43
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.33.11",
3
+ "version": "1.34.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",