@qingfu/core-env 0.5.1 → 0.5.3
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 +2 -3
- package/lib/queue.js +3 -4
- package/lib/utils.js +3 -0
- package/package.json +4 -3
package/lib/helper.js
CHANGED
|
@@ -97,10 +97,9 @@ helper.parseLike = ( ...fields ) => {
|
|
|
97
97
|
|
|
98
98
|
helper.ip2geo = async ( ctx, next ) => {
|
|
99
99
|
try {
|
|
100
|
-
let
|
|
101
|
-
let ip = ctx.ip, agent = ctx.get( 'User-Agent' );
|
|
100
|
+
let user = ctx.state.user, ip = ctx.ip, agent = ctx.get( 'User-Agent' );
|
|
102
101
|
let geo = ctx.state.geo = brokers( 'sign' ) && await brokers( 'sign' ).call( 'detect.geo', { ip });
|
|
103
|
-
if ( brokers( 'qfu' ) &&
|
|
102
|
+
if ( brokers( 'qfu' ) && user && geo ) await brokers( 'qfu' ).call( 'user.refreshGEO', { user, ip, agent, ...geo });
|
|
104
103
|
} catch ( err ) {
|
|
105
104
|
( global.logger || global.console ).warn( err );
|
|
106
105
|
}
|
package/lib/queue.js
CHANGED
|
@@ -28,13 +28,12 @@ if ( process.env.QUEUE_URI ) {
|
|
|
28
28
|
|
|
29
29
|
if ( process.env.BULLMQ_URI ) {
|
|
30
30
|
|
|
31
|
-
const { parseURL } = require( 'ioredis/built/utils' );
|
|
32
31
|
const { Queue, Worker } = require( 'bullmq' );
|
|
33
32
|
const queues = [], workers = [], flows = [];
|
|
34
33
|
const DEFAULT_PREFIX = 'bullmq', DEFAULT_NAME = 'default name';
|
|
35
34
|
|
|
36
35
|
global.BullQueue = _.memoize(( name, options ) => {
|
|
37
|
-
let connection =
|
|
36
|
+
let connection = { url: process.env.BULLMQ_URI };
|
|
38
37
|
let queue = new Queue( name, { connection, prefix: DEFAULT_PREFIX, ...options });
|
|
39
38
|
queue.add = _.wrap( queue.add, function( func, ...args ) {
|
|
40
39
|
if ( !_.isString( args[ 0 ])) args = [ DEFAULT_NAME, ...args ];
|
|
@@ -59,7 +58,7 @@ if ( process.env.BULLMQ_URI ) {
|
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
global.BullWorker = ( name, func, options ) => {
|
|
62
|
-
let connection =
|
|
61
|
+
let connection = { url: process.env.BULLMQ_URI };
|
|
63
62
|
let defaults = { removeOnComplete: { count: 0 }, removeOnFail: { count: 0 }};
|
|
64
63
|
let worker = new Worker( name, func, { connection, prefix: DEFAULT_PREFIX, ...defaults, ...options });
|
|
65
64
|
worker.on( 'error', err => {
|
|
@@ -77,7 +76,7 @@ if ( process.env.BULLMQ_URI ) {
|
|
|
77
76
|
};
|
|
78
77
|
|
|
79
78
|
global.BullFlow = options => {
|
|
80
|
-
let connection =
|
|
79
|
+
let connection = { url: process.env.BULLMQ_URI };
|
|
81
80
|
let flow = new FlowProducer({ connection, prefix: DEFAULT_PREFIX, ...options });
|
|
82
81
|
flow.close = _.wrap( flow.close, function( func, ...args ) {
|
|
83
82
|
_.pull( flows, this );
|
package/lib/utils.js
CHANGED
|
@@ -7,8 +7,11 @@ const baseX = require( 'base-x' ).default;
|
|
|
7
7
|
const pinyin = require( 'pinyin' ).default;
|
|
8
8
|
const qrcode = require( 'qr-image' );
|
|
9
9
|
const request = require( 'superagent' );
|
|
10
|
+
const { serializeError } = require( 'serialize-error' );
|
|
10
11
|
const utils = global.utils = module.exports = {};
|
|
11
12
|
|
|
13
|
+
utils.serializeError = serializeError;
|
|
14
|
+
|
|
12
15
|
utils.xml2json = async ( xml, opts ) => {
|
|
13
16
|
if ( !opts ) opts = { explicitRoot: false, explicitArray: false };
|
|
14
17
|
var parser = new xml2js.Parser( opts );
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qingfu/core-env",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"readmeFilename": "README.md",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@koa/cors": "5.0.0",
|
|
7
|
-
"@koa/router": "13.
|
|
7
|
+
"@koa/router": "13.1.0",
|
|
8
8
|
"base-x": "5.0.0",
|
|
9
9
|
"bull": "4.16.3",
|
|
10
|
-
"bullmq": "5.
|
|
10
|
+
"bullmq": "5.13.1",
|
|
11
11
|
"busboy": "1.6.0",
|
|
12
12
|
"cookie": "0.6.0",
|
|
13
13
|
"dotenv-extended": "2.9.0",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"primus": "8.0.9",
|
|
36
36
|
"primus-rooms": "3.4.3",
|
|
37
37
|
"qr-image": "3.2.0",
|
|
38
|
+
"serialize-error": "8.1.0",
|
|
38
39
|
"superagent": "10.1.0",
|
|
39
40
|
"wechat-encrypt": "1.1.1",
|
|
40
41
|
"winston": "3.14.2",
|