@qingfu/core-env 0.1.24 → 0.1.27

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/lib/helper.js CHANGED
@@ -3,6 +3,24 @@ 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
+ body: _.size( fields ) ? _.pick( body, fields ) : body,
19
+ user: ctx.state.user
20
+ });
21
+ };
22
+ };
23
+
6
24
  helper.multipart = ({ count = 5, size = 20 * 1024 * 1024 } = {}) => {
7
25
  return async ( ctx, next ) => {
8
26
  let fields = {}, files = {};
package/lib/server.js CHANGED
@@ -37,6 +37,7 @@ if ( process.env.HTTP_PORT ) {
37
37
  ctx.status =
38
38
  err.errmsg && err.errmsg.indexOf( 'E11000 duplicate key error' ) !== -1 && 409 ||
39
39
  err.message && err.message.indexOf( 'Cast to ObjectId failed' ) !== -1 && 422 ||
40
+ err.message && err.message.indexOf( 'Boundary not found' ) !== -1 && 406 ||
40
41
  err.name === 'ValidationError' && 422 ||
41
42
  err.code && err.name !== 'MongoServerError' && err.code ||
42
43
  err.status && err.status ||
@@ -56,6 +57,7 @@ if ( process.env.HTTP_PORT ) {
56
57
  logger.error( Object.assign( err, {
57
58
  url: ctx.path,
58
59
  query: ctx.query,
60
+ method: ctx.method,
59
61
  body: ctx.request.body,
60
62
  user: ctx.state.user
61
63
  }));
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.1.24",
3
+ "version": "0.1.27",
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.4",
25
- "mongoose-cast-aggregation": "0.2.1",
24
+ "mongoose": "6.4.4",
25
+ "mongoose-cast-aggregation": "0.3.1",
26
26
  "mongoose-geojson-schema": "2.2.2",
27
- "mongoose-lean-defaults": "2.1.0",
28
- "mongoose-lean-getters": "0.3.2",
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.3",
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"