yakuza0 2.21.5 → 2.21.6-beta.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.
- package/nuxt/modules/index.js +1 -1
- package/nuxt/modules/log.js +19 -0
- package/nuxt/modules/ws.js +10 -7
- package/package.json +1 -1
- package/template/log.plugin.js +89 -0
- package/template/ws.plugin.js +61 -43
- package/utils/inclusive.js +13 -0
package/nuxt/modules/index.js
CHANGED
|
@@ -48,7 +48,7 @@ exports.default = function (config) {
|
|
|
48
48
|
// '@nuxtjs/style-resources',
|
|
49
49
|
// 'nuxt-polyfill',
|
|
50
50
|
// ['nuxt-svg-sprite-loader', {symbolId: 'icon-[name]'}],
|
|
51
|
-
_paths2.default.path.resolve(__dirname, './md.js'), _paths2.default.path.resolve(__dirname, './tfs.js'), _paths2.default.path.resolve(__dirname, './services.js'), _paths2.default.path.resolve(__dirname, './storage.js'), _paths2.default.path.resolve(__dirname, './
|
|
51
|
+
_paths2.default.path.resolve(__dirname, './md.js'), _paths2.default.path.resolve(__dirname, './tfs.js'), _paths2.default.path.resolve(__dirname, './services.js'), _paths2.default.path.resolve(__dirname, './storage.js'), _paths2.default.path.resolve(__dirname, './log.js'), _paths2.default.path.resolve(__dirname, './ws.js'), _paths2.default.path.resolve(__dirname, './http.js'), _paths2.default.path.resolve(__dirname, './console.js'), _paths2.default.path.resolve(__dirname, './init.js'), _paths2.default.path.resolve(__dirname, './redirect.js'), _paths2.default.path.resolve(__dirname, './utils.js'), _paths2.default.path.resolve(__dirname, './yk.js'), _paths2.default.path.resolve(__dirname, './first.js')]);
|
|
52
52
|
|
|
53
53
|
// if (yConf.pkg.yk.nuxt.mds.svg) {
|
|
54
54
|
// mds.push(['nuxt-svg-sprite-loader', {symbolId: 'icon-[name]'}]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
exports.default = function (moduleOptions) {
|
|
8
|
+
this.addPlugin({
|
|
9
|
+
src: _paths2.default.ykTemplate + 'log.plugin.js'
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
var _paths = require('../../config/paths');
|
|
14
|
+
|
|
15
|
+
var _paths2 = _interopRequireDefault(_paths);
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
module.exports = exports['default'];
|
package/nuxt/modules/ws.js
CHANGED
|
@@ -5,14 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
|
|
7
7
|
exports.default = function (moduleOptions) {
|
|
8
|
-
|
|
8
|
+
this.addPlugin({
|
|
9
|
+
src: _paths2.default.ykTemplate + 'ws.plugin.js'
|
|
10
|
+
});
|
|
11
|
+
// const appConf = this.options.appConf;
|
|
9
12
|
|
|
10
|
-
if (!appConf.standAlone) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
// if (!appConf.standAlone) {
|
|
14
|
+
// this.addPlugin({
|
|
15
|
+
// src: paths.ykTemplate + 'ws.plugin.js',
|
|
16
|
+
// ssr: false,
|
|
17
|
+
// })
|
|
18
|
+
// }
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
var _paths = require('../../config/paths');
|
package/package.json
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import yConf from 'yakuza0/config';
|
|
2
|
+
import {connect, req} from 'yakuza1/lib/ws';
|
|
3
|
+
|
|
4
|
+
export default async (ctx, inject) => {
|
|
5
|
+
const { $utils, $http, $yk } = ctx;
|
|
6
|
+
const event = {
|
|
7
|
+
debug: () => {
|
|
8
|
+
},
|
|
9
|
+
info: () => {
|
|
10
|
+
},
|
|
11
|
+
warn: () => {
|
|
12
|
+
},
|
|
13
|
+
error: () => {
|
|
14
|
+
},
|
|
15
|
+
fatal: () => {
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const send = async (body) => {
|
|
20
|
+
if (!yConf.standAlone) {
|
|
21
|
+
if ($utils.checkServer()) {
|
|
22
|
+
try {
|
|
23
|
+
const result = await $http.post('$/feapiv1/log/publish', {
|
|
24
|
+
...body,
|
|
25
|
+
}, {
|
|
26
|
+
hasHook: [],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return result && result.data
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// console.log(e);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
await connect();
|
|
35
|
+
await req('log/publish', {
|
|
36
|
+
body: {
|
|
37
|
+
...body,
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const nowLv = yConf.server.log.levels[yConf.server.log.level];
|
|
45
|
+
const msg = async ({head, detail, type}) => {
|
|
46
|
+
const body = {
|
|
47
|
+
head, detail, type,
|
|
48
|
+
sourceName: yConf.server.log.prefixSourceName + ' -> ' + yConf.name + (yConf.server.log.sourceName ? ' -> ' + yConf.server.log.sourceName : ''),
|
|
49
|
+
streamName: ' -> ' + $yk.appName + (yConf.server.log.streamName ? ' -> ' + yConf.server.log.streamName : ''),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (yConf.server.log.levels[type] >= nowLv) {
|
|
53
|
+
if (yConf.server.log.client && !$utils.checkServer()) {
|
|
54
|
+
console.log('%c['+type.toUpperCase()+']', "color:"+yConf.server.log.colors[type]+";", head)
|
|
55
|
+
console.log(detail)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (yConf.server.log.onlySSR) {
|
|
59
|
+
if (yConf.server.log.server && $utils.checkServer()) {
|
|
60
|
+
await send(body)
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
if (yConf.server.log.server) {
|
|
64
|
+
await send(body)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
event.debug = async (head, detail) => {
|
|
71
|
+
await msg({head, detail, type: 'debug'})
|
|
72
|
+
}
|
|
73
|
+
event.info = async (head, detail) => {
|
|
74
|
+
await msg({head, detail, type: 'info'})
|
|
75
|
+
}
|
|
76
|
+
event.warn = async (head, detail) => {
|
|
77
|
+
await msg({head, detail, type: 'warn'})
|
|
78
|
+
}
|
|
79
|
+
event.error = async (head, detail) => {
|
|
80
|
+
await msg({head, detail, type: 'error'})
|
|
81
|
+
}
|
|
82
|
+
event.fatal = async (head, detail) => {
|
|
83
|
+
await msg({head, detail, type: 'fatal'})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
ctx.$log = event;
|
|
87
|
+
inject('log', event);
|
|
88
|
+
}
|
|
89
|
+
|
package/template/ws.plugin.js
CHANGED
|
@@ -5,6 +5,7 @@ import {connect, req, decrypt} from 'yakuza1/lib/ws';
|
|
|
5
5
|
import {mixin} from 'yakuza1/lib/encrypt';
|
|
6
6
|
|
|
7
7
|
export default async (ctx, inject) => {
|
|
8
|
+
const { $http, $utils, $yk } = ctx;
|
|
8
9
|
const event = {
|
|
9
10
|
publish: () => {
|
|
10
11
|
},
|
|
@@ -17,59 +18,76 @@ export default async (ctx, inject) => {
|
|
|
17
18
|
|
|
18
19
|
const on = {};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (!yConf.standAlone) {
|
|
22
|
+
if ($utils.checkServer()) {
|
|
23
|
+
event.publish = async (topic, message) => {
|
|
24
|
+
try {
|
|
25
|
+
const result = await $http.post('$/feapiv1/mq/publish', {
|
|
26
|
+
topic,
|
|
27
|
+
message,
|
|
28
|
+
}, {
|
|
29
|
+
hasHook: [],
|
|
30
|
+
})
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
on[topic] = []
|
|
32
|
+
return result && result.data
|
|
33
|
+
} catch (e) {}
|
|
26
34
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
} else {
|
|
36
|
+
try {
|
|
37
|
+
const client = await connect();
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
event.on = (topic, callback) => {
|
|
40
|
+
if (!_.isArray(on[topic])) {
|
|
41
|
+
on[topic] = []
|
|
42
|
+
}
|
|
43
|
+
on[topic].push(callback);
|
|
44
|
+
req('mq/subscribe', { body: { topic } });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
event.off = (topic) => {
|
|
48
|
+
on[topic] = []
|
|
49
|
+
req('mq/unsubscribe', { body: { topic } });
|
|
50
|
+
};
|
|
35
51
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
event.publish = (topic, message) => {
|
|
53
|
+
req('mq/publish', {
|
|
54
|
+
body: {
|
|
55
|
+
topic,
|
|
56
|
+
message,
|
|
57
|
+
}
|
|
58
|
+
})
|
|
41
59
|
}
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
60
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
client.on('mq/message', (res) => {
|
|
52
|
-
const key = mixin.getKey(client.id);
|
|
53
|
-
const { topic, message } = decrypt(res, key);
|
|
54
|
-
if (_.isArray(on[topic])) {
|
|
55
|
-
on[topic].forEach(callback => {
|
|
56
|
-
if (typeof callback === 'function') {
|
|
57
|
-
callback(message);
|
|
61
|
+
event.history = async (topic, options = {}) => await req('mq/history', {
|
|
62
|
+
body: {
|
|
63
|
+
topic,
|
|
64
|
+
options,
|
|
58
65
|
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
});
|
|
67
|
+
client.on('mq/message', (res) => {
|
|
68
|
+
const key = mixin.getKey(client.id);
|
|
69
|
+
const { topic, message } = decrypt(res, key);
|
|
70
|
+
if (_.isArray(on[topic])) {
|
|
71
|
+
on[topic].forEach(callback => {
|
|
72
|
+
if (typeof callback === 'function') {
|
|
73
|
+
callback(message);
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
});
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
client.on('reconnect', (attemptNumber) => {
|
|
80
|
+
if (_.isPlainObject(on)) {
|
|
81
|
+
_.forEach(on, (arr, topic) => {
|
|
82
|
+
if (typeof topic === 'string') {
|
|
83
|
+
req('mq/subscribe', { body: { topic } });
|
|
84
|
+
}
|
|
85
|
+
})
|
|
68
86
|
}
|
|
69
|
-
})
|
|
87
|
+
});
|
|
88
|
+
} catch (e) {
|
|
70
89
|
}
|
|
71
|
-
}
|
|
72
|
-
} catch (e) {
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
ctx.$ws = event;
|
package/utils/inclusive.js
CHANGED
|
@@ -302,6 +302,18 @@ var render = function () {
|
|
|
302
302
|
cookieSameSite: 'Lax',
|
|
303
303
|
// ...mainConf.server,
|
|
304
304
|
// ...ykConf.server,
|
|
305
|
+
log: {
|
|
306
|
+
enabled: true,
|
|
307
|
+
onlySSR: true,
|
|
308
|
+
client: true,
|
|
309
|
+
server: true,
|
|
310
|
+
level: 'debug',
|
|
311
|
+
levels: { debug: 0, info: 1, warn: 2, error: 3, fatal: 4 },
|
|
312
|
+
colors: { debug: '#247a6a', info: '#879c22', warn: '#b09d40', error: '#d76b5c', fatal: '#8c7197' },
|
|
313
|
+
sourceName: '',
|
|
314
|
+
streamName: '',
|
|
315
|
+
prefixSourceName: 'CLN框架日志'
|
|
316
|
+
},
|
|
305
317
|
csp: {
|
|
306
318
|
enabled: true,
|
|
307
319
|
strict: false,
|
|
@@ -884,6 +896,7 @@ var render = function () {
|
|
|
884
896
|
|
|
885
897
|
v.server = (0, _extends3.default)({}, conf.server, v.server, {
|
|
886
898
|
f5Offline: checkBool(conf.server.f5Offline, v.server && v.server.f5Offline),
|
|
899
|
+
log: (0, _extends3.default)({}, conf.server.log, v.server && v.server.log),
|
|
887
900
|
browsers: {
|
|
888
901
|
redirect: (0, _extends3.default)({}, conf.server && conf.server.browsers && conf.server.browsers.redirect, v.server && v.server.browsers && v.server.browsers.redirect),
|
|
889
902
|
static: v.server && v.server.browsers && v.server.browsers.static || conf.server && conf.server.browsers && conf.server.browsers.static
|