@qingfu/core-env 0.1.25 → 0.1.26

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/lib/helper.js +17 -0
  2. package/package.json +9 -9
package/lib/helper.js CHANGED
@@ -3,6 +3,23 @@ const stream = require( 'stream' );
3
3
  const WXEncrypt = require( 'wechat-encrypt' );
4
4
  const helper = global.helper = module.exports = {};
5
5
 
6
+ helper.recordTime = ({ fields, threshold = ms( '30s' )} = {}) => {
7
+ return async ( ctx, next ) => {
8
+ let body = Object.assign({}, ctx.query, ctx.request.body );
9
+ let timeStart = Date.now();
10
+ await next();
11
+ let timeFinish = Date.now();
12
+ if ( timeFinish - timeStart > threshold )
13
+ ( global.logger || global.console ).error({
14
+ url: ctx.path, method: ctx.method,
15
+ start: new Date( timeStart ).format( 'yyyy-MM-dd hh:mm:ss' ),
16
+ finish: new Date( timeFinish ).format( 'yyyy-MM-dd hh:mm:ss' ),
17
+ seconds: +(( timeFinish - timeStart ) / 1000 ).toFixed( 2 ),
18
+ user: ctx.state.user, body: _.size( fields ) ? _.pick( body, fields ) : body
19
+ });
20
+ };
21
+ };
22
+
6
23
  helper.multipart = ({ count = 5, size = 20 * 1024 * 1024 } = {}) => {
7
24
  return async ( ctx, next ) => {
8
25
  let fields = {}, files = {};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "readmeFilename": "README.md",
5
5
  "dependencies": {
6
6
  "@koa/cors": "3.3.0",
7
- "@koa/router": "10.1.1",
8
- "bull": "4.8.3",
7
+ "@koa/router": "11.0.1",
8
+ "bull": "4.8.4",
9
9
  "busboy": "0.3.1",
10
10
  "cookie": "0.5.0",
11
11
  "dotenv-extended": "2.9.0",
@@ -21,11 +21,11 @@
21
21
  "koa-qs": "3.0.0",
22
22
  "lodash": "4.17.21",
23
23
  "moleculer": "0.14.21",
24
- "mongoose": "6.3.6",
25
- "mongoose-cast-aggregation": "0.2.1",
24
+ "mongoose": "6.4.3",
25
+ "mongoose-cast-aggregation": "0.3.0",
26
26
  "mongoose-geojson-schema": "2.2.2",
27
- "mongoose-lean-defaults": "2.1.1",
28
- "mongoose-lean-getters": "0.3.3",
27
+ "mongoose-lean-defaults": "2.2.1",
28
+ "mongoose-lean-getters": "0.3.4",
29
29
  "mongoose-lean-virtuals": "0.9.1",
30
30
  "ms": "2.1.3",
31
31
  "notepack.io": "2.3.0",
@@ -33,9 +33,9 @@
33
33
  "primus": "8.0.6",
34
34
  "primus-rooms": "3.4.1",
35
35
  "qr-image": "3.2.0",
36
- "superagent": "7.1.6",
36
+ "superagent": "8.0.0",
37
37
  "wechat-encrypt": "1.1.1",
38
- "winston": "3.7.2",
38
+ "winston": "3.8.1",
39
39
  "winston-mongodb": "5.0.7",
40
40
  "xlsx": "0.18.5",
41
41
  "xml2js": "0.4.23"