@jayfong/x-server 1.34.0 → 1.34.2

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.
@@ -97,6 +97,9 @@ class Server {
97
97
  this.fastify.route({
98
98
  method: serverMethod,
99
99
  url: item.path,
100
+ constraints: handlerOptions.requestHost ? {
101
+ host: handlerOptions.requestHost
102
+ } : undefined,
100
103
  websocket: isWS,
101
104
  handler: async (req, res) => {
102
105
  const url = `${appUrl}${// 结构:/test/sss?x=2
@@ -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
  }
@@ -82,6 +82,9 @@ export class Server {
82
82
  this.fastify.route({
83
83
  method: serverMethod,
84
84
  url: item.path,
85
+ constraints: handlerOptions.requestHost ? {
86
+ host: handlerOptions.requestHost
87
+ } : undefined,
85
88
  websocket: isWS,
86
89
  handler: async (req, res) => {
87
90
  const url = `${appUrl}${// 结构:/test/sss?x=2
@@ -102,6 +102,10 @@ export declare namespace XHandler {
102
102
  * @default POST
103
103
  */
104
104
  requestMethod?: TReqMethod;
105
+ /**
106
+ * 请求 Host
107
+ */
108
+ requestHost?: string | RegExp;
105
109
  /**
106
110
  * 请求路径
107
111
  */
@@ -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.34.0",
3
+ "version": "1.34.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",