@jayfong/x-server 1.24.1 → 1.26.0
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/CHANGELOG.md +23 -0
- package/lib/_cjs/core/server.js +6 -2
- package/lib/_cjs/index.js +16 -0
- package/lib/_cjs/plugins/form_body_parser.js +24 -0
- package/lib/_cjs/services/pay.js +19 -18
- package/lib/_cjs/services/sensitive_words.js +32 -0
- package/lib/core/server.js +6 -2
- package/lib/core/types.d.ts +9 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/plugins/form_body_parser.d.ts +13 -0
- package/lib/plugins/form_body_parser.js +15 -0
- package/lib/services/pay.d.ts +3 -3
- package/lib/services/pay.js +19 -17
- package/lib/services/sensitive_words.d.ts +16 -0
- package/lib/services/sensitive_words.js +22 -0
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.26.0](https://github.com/jfWorks/x-server/compare/v1.25.0...v1.26.0) (2022-05-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add SensitiveWordsService ([ee03592](https://github.com/jfWorks/x-server/commit/ee03592f5acd795b03fa65717ea276db66f453c1))
|
|
11
|
+
|
|
12
|
+
## [1.25.0](https://github.com/jfWorks/x-server/compare/v1.24.2...v1.25.0) (2022-05-02)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add FormBodyParserPlugin ([b51392c](https://github.com/jfWorks/x-server/commit/b51392c5dce6480f9f5250192f676421c6a1cad2))
|
|
18
|
+
* ctx add req res ([ccd1ea0](https://github.com/jfWorks/x-server/commit/ccd1ea08f9d10e0b29ff235b1b6572b180798d8d))
|
|
19
|
+
|
|
20
|
+
### [1.24.2](https://github.com/jfWorks/x-server/compare/v1.24.1...v1.24.2) (2022-05-02)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* returnUrl? ([fb46884](https://github.com/jfWorks/x-server/commit/fb4688405c16986727be2785695e9faa6a2db386))
|
|
26
|
+
* verifyNotifyData ([a4b76e3](https://github.com/jfWorks/x-server/commit/a4b76e3c63babc2f789646f932b1375a1c0a76e4))
|
|
27
|
+
|
|
5
28
|
### [1.24.1](https://github.com/jfWorks/x-server/compare/v1.24.0...v1.24.1) (2022-05-02)
|
|
6
29
|
|
|
7
30
|
## [1.24.0](https://github.com/jfWorks/x-server/compare/v1.23.0...v1.24.0) (2022-05-02)
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -104,7 +104,9 @@ class Server {
|
|
|
104
104
|
headers: req.headers,
|
|
105
105
|
setHeader: (k, v) => res.header(k, v),
|
|
106
106
|
redirect: undefined,
|
|
107
|
-
ws: req
|
|
107
|
+
ws: req,
|
|
108
|
+
req: req,
|
|
109
|
+
res: res
|
|
108
110
|
});
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
@@ -132,7 +134,9 @@ class Server {
|
|
|
132
134
|
headers: req.headers,
|
|
133
135
|
setHeader: (k, v) => res.header(k, v),
|
|
134
136
|
redirect: url => res.redirect(url),
|
|
135
|
-
ws: undefined
|
|
137
|
+
ws: undefined,
|
|
138
|
+
req: req,
|
|
139
|
+
res: res
|
|
136
140
|
});
|
|
137
141
|
return data;
|
|
138
142
|
}
|
package/lib/_cjs/index.js
CHANGED
|
@@ -114,6 +114,14 @@ Object.keys(_file_parser).forEach(function (key) {
|
|
|
114
114
|
exports[key] = _file_parser[key];
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
var _form_body_parser = require("./plugins/form_body_parser");
|
|
118
|
+
|
|
119
|
+
Object.keys(_form_body_parser).forEach(function (key) {
|
|
120
|
+
if (key === "default" || key === "__esModule") return;
|
|
121
|
+
if (key in exports && exports[key] === _form_body_parser[key]) return;
|
|
122
|
+
exports[key] = _form_body_parser[key];
|
|
123
|
+
});
|
|
124
|
+
|
|
117
125
|
var _ws_parser = require("./plugins/ws_parser");
|
|
118
126
|
|
|
119
127
|
Object.keys(_ws_parser).forEach(function (key) {
|
|
@@ -202,6 +210,14 @@ Object.keys(_redis).forEach(function (key) {
|
|
|
202
210
|
exports[key] = _redis[key];
|
|
203
211
|
});
|
|
204
212
|
|
|
213
|
+
var _sensitive_words = require("./services/sensitive_words");
|
|
214
|
+
|
|
215
|
+
Object.keys(_sensitive_words).forEach(function (key) {
|
|
216
|
+
if (key === "default" || key === "__esModule") return;
|
|
217
|
+
if (key in exports && exports[key] === _sensitive_words[key]) return;
|
|
218
|
+
exports[key] = _sensitive_words[key];
|
|
219
|
+
});
|
|
220
|
+
|
|
205
221
|
var _x = require("./x");
|
|
206
222
|
|
|
207
223
|
Object.keys(_x).forEach(function (key) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.FormBodyParserPlugin = void 0;
|
|
7
|
+
|
|
8
|
+
var _formbody = _interopRequireDefault(require("@fastify/formbody"));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* POST application/x-www-form-urlencoded 解析器插件
|
|
12
|
+
*/
|
|
13
|
+
class FormBodyParserPlugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
register(fastify) {
|
|
19
|
+
fastify.register(_formbody.default, this.options);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.FormBodyParserPlugin = FormBodyParserPlugin;
|
package/lib/_cjs/services/pay.js
CHANGED
|
@@ -15,8 +15,6 @@ var _got = _interopRequireDefault(require("got"));
|
|
|
15
15
|
|
|
16
16
|
var _http_error = require("../core/http_error");
|
|
17
17
|
|
|
18
|
-
var _x = require("../x");
|
|
19
|
-
|
|
20
18
|
class PayService {
|
|
21
19
|
constructor(options) {
|
|
22
20
|
this.options = options;
|
|
@@ -33,18 +31,21 @@ class PayService {
|
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
const token = await _x.x.cache.save('x', '1h');
|
|
37
34
|
const formData = new _form.default();
|
|
38
35
|
formData.setMethod('get');
|
|
39
36
|
formData.addField('notifyUrl', options.notifyUrl);
|
|
40
|
-
|
|
37
|
+
|
|
38
|
+
if (options.returnUrl) {
|
|
39
|
+
formData.addField('returnUrl', options.returnUrl);
|
|
40
|
+
}
|
|
41
|
+
|
|
41
42
|
formData.addField('bizContent', {
|
|
42
43
|
outTradeNo: options.tradeNumber,
|
|
43
44
|
productCode: 'FAST_INSTANT_TRADE_PAY',
|
|
44
45
|
totalAmount: options.totalMoney,
|
|
45
46
|
subject: options.goodsName,
|
|
46
47
|
goodsType: '0',
|
|
47
|
-
passbackParams:
|
|
48
|
+
passbackParams: 'alipay'
|
|
48
49
|
});
|
|
49
50
|
const payUrl = await this.alipaySdk.exec('alipay.trade.page.pay', {}, {
|
|
50
51
|
formData: formData
|
|
@@ -55,13 +56,12 @@ class PayService {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
async prepareWepay(options) {
|
|
58
|
-
const token = await _x.x.cache.save('x', '1h');
|
|
59
59
|
const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
|
|
60
60
|
appid: this.options.wepay.appId,
|
|
61
61
|
mchid: this.options.wepay.merchantId,
|
|
62
62
|
description: options.goodsName,
|
|
63
63
|
out_trade_no: options.tradeNumber,
|
|
64
|
-
attach:
|
|
64
|
+
attach: 'wepay',
|
|
65
65
|
notify_url: options.notifyUrl,
|
|
66
66
|
amount: {
|
|
67
67
|
total: options.totalMoney * 100,
|
|
@@ -91,19 +91,20 @@ class PayService {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
verifyNotifyData(data) {
|
|
95
|
+
try {
|
|
96
|
+
var _this$alipaySdk;
|
|
97
|
+
|
|
98
|
+
return !!data && typeof data === 'object' && ( // 支付宝
|
|
99
|
+
data.passback_params === 'alipay' ? !!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data)) : // 微信支付
|
|
100
|
+
data.resource ? JSON.parse(this.wepayDecrypt(data.resource)).attach === 'wepay' : false);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
if (!
|
|
106
|
+
verifyNotifyDataOrFail(data, message) {
|
|
107
|
+
if (!this.verifyNotifyData(data)) {
|
|
107
108
|
throw new _http_error.HttpError.BadRequest(message);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.SensitiveWordsService = void 0;
|
|
7
|
+
|
|
8
|
+
var _mintFilter = _interopRequireDefault(require("mint-filter"));
|
|
9
|
+
|
|
10
|
+
class SensitiveWordsService {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.serviceName = 'sensitiveWords';
|
|
14
|
+
this.mint = void 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async filter(text) {
|
|
18
|
+
if (!this.mint) {
|
|
19
|
+
this.mint = new _mintFilter.default(this.options.words);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const res = await this.mint.filter(text, {
|
|
23
|
+
every: true,
|
|
24
|
+
replace: true,
|
|
25
|
+
words: false
|
|
26
|
+
});
|
|
27
|
+
return res.text;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.SensitiveWordsService = SensitiveWordsService;
|
package/lib/core/server.js
CHANGED
|
@@ -89,7 +89,9 @@ export class Server {
|
|
|
89
89
|
headers: req.headers,
|
|
90
90
|
setHeader: (k, v) => res.header(k, v),
|
|
91
91
|
redirect: undefined,
|
|
92
|
-
ws: req
|
|
92
|
+
ws: req,
|
|
93
|
+
req: req,
|
|
94
|
+
res: res
|
|
93
95
|
});
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
@@ -117,7 +119,9 @@ export class Server {
|
|
|
117
119
|
headers: req.headers,
|
|
118
120
|
setHeader: (k, v) => res.header(k, v),
|
|
119
121
|
redirect: url => res.redirect(url),
|
|
120
|
-
ws: undefined
|
|
122
|
+
ws: undefined,
|
|
123
|
+
req: req,
|
|
124
|
+
res: res
|
|
121
125
|
});
|
|
122
126
|
return data;
|
|
123
127
|
}
|
package/lib/core/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BasePlugin } from '../plugins/base';
|
|
3
3
|
import { BaseService } from '../services/base';
|
|
4
|
+
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
4
5
|
import { yup } from 'vtils/validator';
|
|
5
6
|
import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
|
|
6
7
|
import type { DisposeService } from '../services/dispose';
|
|
@@ -65,6 +66,14 @@ export declare namespace XHandler {
|
|
|
65
66
|
* WS
|
|
66
67
|
*/
|
|
67
68
|
ws: SocketStream;
|
|
69
|
+
/**
|
|
70
|
+
* Fastify Request
|
|
71
|
+
*/
|
|
72
|
+
req: FastifyRequest;
|
|
73
|
+
/**
|
|
74
|
+
* Fastify Response
|
|
75
|
+
*/
|
|
76
|
+
res: FastifyReply;
|
|
68
77
|
}
|
|
69
78
|
type Handle<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method> = (
|
|
70
79
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './core/types';
|
|
|
12
12
|
export * from './plugins/base';
|
|
13
13
|
export * from './plugins/cors';
|
|
14
14
|
export * from './plugins/file_parser';
|
|
15
|
+
export * from './plugins/form_body_parser';
|
|
15
16
|
export * from './plugins/ws_parser';
|
|
16
17
|
export * from './plugins/xml_parser';
|
|
17
18
|
export * from './services/base';
|
|
@@ -23,5 +24,6 @@ export * from './services/mail';
|
|
|
23
24
|
export * from './services/pay';
|
|
24
25
|
export * from './services/rate_limit';
|
|
25
26
|
export * from './services/redis';
|
|
27
|
+
export * from './services/sensitive_words';
|
|
26
28
|
export * from './x';
|
|
27
29
|
export * from '.x/models';
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./core/types";
|
|
|
13
13
|
export * from "./plugins/base";
|
|
14
14
|
export * from "./plugins/cors";
|
|
15
15
|
export * from "./plugins/file_parser";
|
|
16
|
+
export * from "./plugins/form_body_parser";
|
|
16
17
|
export * from "./plugins/ws_parser";
|
|
17
18
|
export * from "./plugins/xml_parser";
|
|
18
19
|
export * from "./services/base";
|
|
@@ -24,6 +25,7 @@ export * from "./services/mail";
|
|
|
24
25
|
export * from "./services/pay";
|
|
25
26
|
export * from "./services/rate_limit";
|
|
26
27
|
export * from "./services/redis";
|
|
28
|
+
export * from "./services/sensitive_words";
|
|
27
29
|
export * from "./x"; // @endindex
|
|
28
30
|
// @ts-ignore
|
|
29
31
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FormBodyPluginOptions } from '@fastify/formbody';
|
|
2
|
+
import { BasePlugin } from './base';
|
|
3
|
+
import { FastifyInstance } from 'fastify';
|
|
4
|
+
export interface FormBodyParserPluginOptions extends FormBodyPluginOptions {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* POST application/x-www-form-urlencoded 解析器插件
|
|
8
|
+
*/
|
|
9
|
+
export declare class FormBodyParserPlugin implements BasePlugin {
|
|
10
|
+
private options?;
|
|
11
|
+
constructor(options?: FormBodyParserPluginOptions);
|
|
12
|
+
register(fastify: FastifyInstance): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import FastifyFormBody from '@fastify/formbody';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* POST application/x-www-form-urlencoded 解析器插件
|
|
5
|
+
*/
|
|
6
|
+
export class FormBodyParserPlugin {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
register(fastify) {
|
|
12
|
+
fastify.register(FastifyFormBody, this.options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
package/lib/services/pay.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface PayPrepareAlipayOptions {
|
|
|
33
33
|
/** 通知地址(POST) */
|
|
34
34
|
notifyUrl: string;
|
|
35
35
|
/** 返回地址 */
|
|
36
|
-
returnUrl
|
|
36
|
+
returnUrl?: string;
|
|
37
37
|
}
|
|
38
38
|
export interface PayPrepareAlipayResult {
|
|
39
39
|
/** 支付地址,需跳转过去 */
|
|
@@ -69,8 +69,8 @@ export declare class PayService implements BaseService {
|
|
|
69
69
|
constructor(options: PayOptions);
|
|
70
70
|
prepareAlipay(options: PayPrepareAlipayOptions): Promise<PayPrepareAlipayResult>;
|
|
71
71
|
prepareWepay(options: PayPrepareWepayOptions): Promise<PayPrepareWepayResult>;
|
|
72
|
-
verifyNotifyData(data: any):
|
|
73
|
-
verifyNotifyDataOrFail(data: any, message?: string):
|
|
72
|
+
verifyNotifyData(data: any): boolean;
|
|
73
|
+
verifyNotifyDataOrFail(data: any, message?: string): void;
|
|
74
74
|
private wepaySign;
|
|
75
75
|
private wepayDecrypt;
|
|
76
76
|
private wepayRequest;
|
package/lib/services/pay.js
CHANGED
|
@@ -3,7 +3,6 @@ import AlipaySdk from 'alipay-sdk';
|
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import got from 'got';
|
|
5
5
|
import { HttpError } from "../core/http_error";
|
|
6
|
-
import { x } from "../x";
|
|
7
6
|
export class PayService {
|
|
8
7
|
constructor(options) {
|
|
9
8
|
this.options = options;
|
|
@@ -20,18 +19,21 @@ export class PayService {
|
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
const token = await x.cache.save('x', '1h');
|
|
24
22
|
const formData = new AlipayFormData();
|
|
25
23
|
formData.setMethod('get');
|
|
26
24
|
formData.addField('notifyUrl', options.notifyUrl);
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
if (options.returnUrl) {
|
|
27
|
+
formData.addField('returnUrl', options.returnUrl);
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
formData.addField('bizContent', {
|
|
29
31
|
outTradeNo: options.tradeNumber,
|
|
30
32
|
productCode: 'FAST_INSTANT_TRADE_PAY',
|
|
31
33
|
totalAmount: options.totalMoney,
|
|
32
34
|
subject: options.goodsName,
|
|
33
35
|
goodsType: '0',
|
|
34
|
-
passbackParams:
|
|
36
|
+
passbackParams: 'alipay'
|
|
35
37
|
});
|
|
36
38
|
const payUrl = await this.alipaySdk.exec('alipay.trade.page.pay', {}, {
|
|
37
39
|
formData: formData
|
|
@@ -42,13 +44,12 @@ export class PayService {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async prepareWepay(options) {
|
|
45
|
-
const token = await x.cache.save('x', '1h');
|
|
46
47
|
const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
|
|
47
48
|
appid: this.options.wepay.appId,
|
|
48
49
|
mchid: this.options.wepay.merchantId,
|
|
49
50
|
description: options.goodsName,
|
|
50
51
|
out_trade_no: options.tradeNumber,
|
|
51
|
-
attach:
|
|
52
|
+
attach: 'wepay',
|
|
52
53
|
notify_url: options.notifyUrl,
|
|
53
54
|
amount: {
|
|
54
55
|
total: options.totalMoney * 100,
|
|
@@ -78,19 +79,20 @@ export class PayService {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
verifyNotifyData(data) {
|
|
83
|
+
try {
|
|
84
|
+
var _this$alipaySdk;
|
|
85
|
+
|
|
86
|
+
return !!data && typeof data === 'object' && ( // 支付宝
|
|
87
|
+
data.passback_params === 'alipay' ? !!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data)) : // 微信支付
|
|
88
|
+
data.resource ? JSON.parse(this.wepayDecrypt(data.resource)).attach === 'wepay' : false);
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
if (!
|
|
94
|
+
verifyNotifyDataOrFail(data, message) {
|
|
95
|
+
if (!this.verifyNotifyData(data)) {
|
|
94
96
|
throw new HttpError.BadRequest(message);
|
|
95
97
|
}
|
|
96
98
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseService } from './base';
|
|
2
|
+
export interface SensitiveWordsOptions {
|
|
3
|
+
words: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare class SensitiveWordsService implements BaseService {
|
|
6
|
+
private options;
|
|
7
|
+
serviceName: string;
|
|
8
|
+
private mint;
|
|
9
|
+
constructor(options: SensitiveWordsOptions);
|
|
10
|
+
filter(text: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
declare module '../x' {
|
|
13
|
+
interface X {
|
|
14
|
+
sensitiveWords: SensitiveWordsService;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Mint from 'mint-filter';
|
|
2
|
+
export class SensitiveWordsService {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
this.serviceName = 'sensitiveWords';
|
|
6
|
+
this.mint = void 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async filter(text) {
|
|
10
|
+
if (!this.mint) {
|
|
11
|
+
this.mint = new Mint(this.options.words);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const res = await this.mint.filter(text, {
|
|
15
|
+
every: true,
|
|
16
|
+
replace: true,
|
|
17
|
+
words: false
|
|
18
|
+
});
|
|
19
|
+
return res.text;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@fastify/formbody": "^6.0.0",
|
|
29
30
|
"@prisma/client": "^3.12.0",
|
|
30
31
|
"@types/bull": "^3.15.8",
|
|
31
32
|
"@types/busboy": "^0.3.2",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"ioredis": "^4.28.5",
|
|
57
58
|
"jsonwebtoken": "^8.5.1",
|
|
58
59
|
"mini-svg-data-uri": "^1.4.4",
|
|
60
|
+
"mint-filter": "^3.0.1",
|
|
59
61
|
"node-ssh": "^12.0.4",
|
|
60
62
|
"nodemailer": "^6.7.3",
|
|
61
63
|
"pino-pretty": "^7.6.1",
|