isite 2022.9.16 → 2022.9.18
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/apps/client-side/app.js +2 -3
- package/apps/client-side/site_files/css/bootstrap5-addon.css +2 -2
- package/apps/client-side/site_files/css/layout.css +0 -6
- package/apps/client-side/site_files/html/directive/i-checkbox.html +1 -1
- package/apps/client-side/site_files/js/bootstrap-5-directive.js +1 -5
- package/apps/client-side/site_files/js/last.js +8 -3
- package/apps/client-side/site_files/js/site.js +13 -1
- package/index.js +1 -16
- package/isite_files/html/browser.html +1 -1
- package/lib/collection.js +810 -809
- package/lib/mongodb.js +18 -22
- package/lib/parser.js +9 -9
- package/lib/routing.js +11 -7
- package/lib/session.js +147 -136
- package/lib/sessions.js +91 -26
- package/lib/ws.js +225 -221
- package/object-options/index.js +2 -2
- package/object-options/lib/fn.js +5 -2
- package/package.json +2 -2
- package/server.md +21 -0
- package/lib/setting.js +0 -59
package/lib/mongodb.js
CHANGED
|
@@ -52,31 +52,28 @@ module.exports = function init(____0) {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
_mongo.handleDoc = function (doc) {
|
|
55
|
+
|
|
55
56
|
if (!doc) {
|
|
56
57
|
return doc;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
if (typeof doc === '
|
|
60
|
+
if (typeof doc === 'array') {
|
|
61
|
+
doc.forEach((v, i) => {
|
|
62
|
+
doc[i] = _mongo.handleDoc(v);
|
|
63
|
+
});
|
|
64
|
+
return doc;
|
|
65
|
+
} else if (typeof doc === 'object') {
|
|
60
66
|
for (let key in doc) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (typeof key === 'string') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (typeof val === 'object') {
|
|
71
|
-
val = _mongo.handleDoc(val);
|
|
72
|
-
} else if (typeof val === 'array') {
|
|
73
|
-
val.forEach((v) => {
|
|
74
|
-
v = _mongo.handleDoc(v);
|
|
67
|
+
if (typeof key === 'string' && key.indexOf('$') === 0) {
|
|
68
|
+
delete doc[key];
|
|
69
|
+
} else if (typeof doc[key] === 'string' && ____0.fn.isDate(doc[key])) {
|
|
70
|
+
doc[key] = new Date(doc[key]);
|
|
71
|
+
} else if (typeof doc[key] === 'object') {
|
|
72
|
+
doc[key] = _mongo.handleDoc(doc[key]);
|
|
73
|
+
} else if (typeof doc[key] === 'array') {
|
|
74
|
+
doc[key].forEach((v, i) => {
|
|
75
|
+
doc[key][i] = _mongo.handleDoc(v);
|
|
75
76
|
});
|
|
76
|
-
} else if (typeof val === 'string') {
|
|
77
|
-
if (____0.fn.isDate(val)) {
|
|
78
|
-
doc[key] = new Date(val);
|
|
79
|
-
}
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
}
|
|
@@ -305,7 +302,6 @@ module.exports = function init(____0) {
|
|
|
305
302
|
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName).insertMany(obj.docs, obj.options, function (err, result) {
|
|
306
303
|
if (!err) {
|
|
307
304
|
callback(null, obj.docs, result);
|
|
308
|
-
console.log(' Sessions Saved : ' + obj.docs.length);
|
|
309
305
|
if (____0.options.mongodb.events) {
|
|
310
306
|
____0.call('mongodb after insert many', {
|
|
311
307
|
db: obj.dbName,
|
|
@@ -314,12 +310,12 @@ module.exports = function init(____0) {
|
|
|
314
310
|
});
|
|
315
311
|
}
|
|
316
312
|
} else {
|
|
317
|
-
console.error('
|
|
313
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
318
314
|
callback(err, obj.docs, result);
|
|
319
315
|
}
|
|
320
316
|
});
|
|
321
317
|
} else {
|
|
322
|
-
console.error('
|
|
318
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
323
319
|
callback(err);
|
|
324
320
|
}
|
|
325
321
|
});
|
package/lib/parser.js
CHANGED
|
@@ -180,6 +180,13 @@ module.exports = function init(req, res, ____0, route) {
|
|
|
180
180
|
return out;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
function renderSetting(v) {
|
|
184
|
+
if (v && v == '*') {
|
|
185
|
+
return JSON.stringify(____0.setting);
|
|
186
|
+
} else {
|
|
187
|
+
return render_site('setting.' + v);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
183
190
|
function render_req(v) {
|
|
184
191
|
if (!v) {
|
|
185
192
|
return '';
|
|
@@ -240,7 +247,7 @@ module.exports = function init(req, res, ____0, route) {
|
|
|
240
247
|
ip: req.session.ip,
|
|
241
248
|
requestesCount: req.session.requestesCount,
|
|
242
249
|
busy: req.session.$busy,
|
|
243
|
-
|
|
250
|
+
ipLookup: req.session.ip_list.find((info) => info.ip == req.session.ip),
|
|
244
251
|
});
|
|
245
252
|
}
|
|
246
253
|
if (v == 'lang') {
|
|
@@ -276,13 +283,6 @@ module.exports = function init(req, res, ____0, route) {
|
|
|
276
283
|
}
|
|
277
284
|
}
|
|
278
285
|
|
|
279
|
-
function renderSetting(v) {
|
|
280
|
-
if (v && v == '*') {
|
|
281
|
-
return JSON.stringify(____0.setting.list);
|
|
282
|
-
}
|
|
283
|
-
return ____0.setting.get(v).value;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
286
|
function getContent(name) {
|
|
287
287
|
let path = null;
|
|
288
288
|
|
|
@@ -350,7 +350,7 @@ module.exports = function init(req, res, ____0, route) {
|
|
|
350
350
|
|
|
351
351
|
function renderHtml($, log) {
|
|
352
352
|
$('[x-setting]').each(function (i, elem) {
|
|
353
|
-
if (
|
|
353
|
+
if (____0.setting[$(this).attr('x-setting')] !== true) {
|
|
354
354
|
$(this).remove();
|
|
355
355
|
}
|
|
356
356
|
});
|
package/lib/routing.js
CHANGED
|
@@ -595,7 +595,6 @@ module.exports = function init(____0) {
|
|
|
595
595
|
}
|
|
596
596
|
});
|
|
597
597
|
if (!ok) {
|
|
598
|
-
|
|
599
598
|
if (route.name.contains(____0.strings[16])) {
|
|
600
599
|
res.status(401);
|
|
601
600
|
return res.json({
|
|
@@ -935,6 +934,11 @@ module.exports = function init(____0) {
|
|
|
935
934
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
936
935
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
937
936
|
}
|
|
937
|
+
} else if (name.endsWith('.webp')) {
|
|
938
|
+
res.set(____0.strings[7], 'image/webp');
|
|
939
|
+
if (____0.options.cache.enabled && req.route.cache) {
|
|
940
|
+
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
941
|
+
}
|
|
938
942
|
}
|
|
939
943
|
res.end(req.content, ____0.getFileEncode(name));
|
|
940
944
|
});
|
|
@@ -1196,6 +1200,11 @@ module.exports = function init(____0) {
|
|
|
1196
1200
|
_0xrrxo.start = function (_ports, callback) {
|
|
1197
1201
|
____0.startTime = Date.now();
|
|
1198
1202
|
|
|
1203
|
+
____0.https.globalAgent.options = {
|
|
1204
|
+
key: ____0.fs.readFileSync( ____0.options.https.key || __dirname + '/../ssl/key.pem'),
|
|
1205
|
+
cert: ____0.fs.readFileSync(____0.options.https.cert || __dirname + '/../ssl/cert.pem'),
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1199
1208
|
const ports = [];
|
|
1200
1209
|
|
|
1201
1210
|
if (_ports && ____0.typeof(_ports) !== 'Array') {
|
|
@@ -1230,14 +1239,9 @@ module.exports = function init(____0) {
|
|
|
1230
1239
|
});
|
|
1231
1240
|
|
|
1232
1241
|
if (____0.options.https.enabled) {
|
|
1233
|
-
const https_options = {
|
|
1234
|
-
key: ____0.fs.readFileSync(____0.options.https.key || __dirname + '/../ssl/key.pem'),
|
|
1235
|
-
cert: ____0.fs.readFileSync(____0.options.https.cert || __dirname + '/../ssl/cert.pem'),
|
|
1236
|
-
};
|
|
1237
|
-
|
|
1238
1242
|
____0.options.https.ports.forEach((p, i) => {
|
|
1239
1243
|
let index = ____0.servers.length;
|
|
1240
|
-
____0.servers[index] = ____0.https.createServer(
|
|
1244
|
+
____0.servers[index] = ____0.https.createServer(_0xrrxo.handleServer);
|
|
1241
1245
|
____0.servers[index].listen(p, function () {
|
|
1242
1246
|
____0.log('');
|
|
1243
1247
|
____0.log('-----------------------------------------');
|
package/lib/session.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
module.exports = function init(req, res, ____0, callback) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
____0.getSession({ accessToken: req.cookie('access_token') || req.headers['Access-Token'] || req.headers['access-token'] }, (session) => {
|
|
4
3
|
if (!session.accessToken) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
session.accessToken = new Date().getTime().toString() + '_' + Math.random() * (10000 - 1000) + 1000;
|
|
5
|
+
session.accessToken = ____0.x0md50x(session.accessToken);
|
|
6
|
+
res.cookie('access_token', session.accessToken);
|
|
7
|
+
res.set('Access-Token', session.accessToken);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
session.ip = req.ip;
|
|
@@ -13,155 +12,167 @@ module.exports = function init(req, res, ____0, callback) {
|
|
|
13
12
|
____0.saveSession(session);
|
|
14
13
|
|
|
15
14
|
function AssignFeatures() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
____0.options.defaults.features.forEach((f) => {
|
|
16
|
+
req.features.push(f);
|
|
17
|
+
});
|
|
18
|
+
____0.features.forEach((f) => {
|
|
19
|
+
req.features.push(f.name);
|
|
20
|
+
});
|
|
21
|
+
if (____0.options.dynamic) {
|
|
22
|
+
req.features.push('site.dynamic');
|
|
23
|
+
}
|
|
24
|
+
req.features.push('ip.' + req.ip);
|
|
25
|
+
|
|
26
|
+
if (req.headers['host']) {
|
|
27
|
+
req.features.push('host.' + req.headers['host']);
|
|
28
|
+
req.headers['host'].split('.').forEach((h) => {
|
|
29
|
+
req.features.push('host.' + h);
|
|
21
30
|
});
|
|
22
|
-
|
|
23
|
-
req.features.push('site.dynamic');
|
|
24
|
-
}
|
|
25
|
-
req.features.push('ip.' + req.ip);
|
|
31
|
+
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
if (req.cookies.obj && req.cookies.obj['_ga'] && req.cookies.obj['_ga'].contains('sb')) {
|
|
34
|
+
req.features.push('browser.social');
|
|
35
|
+
req.features.push('browser.social.app');
|
|
36
|
+
}
|
|
37
|
+
if (req.cookies.obj && req.cookies.obj['_gab'] && req.cookies.obj['_gab'].contains('sb')) {
|
|
38
|
+
req.features.push('browser.social');
|
|
39
|
+
req.features.push('browser.social.app');
|
|
40
|
+
}
|
|
41
|
+
if (req.headers['x-browser'] && req.headers['x-browser'].contains('social-browser')) {
|
|
42
|
+
req.features.push('browser.social');
|
|
43
|
+
req.features.push('browser.social.app');
|
|
44
|
+
}
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
if (req.headers['user-agent']) {
|
|
47
|
+
req.userAgent = req.headers['user-agent'].toLowerCase();
|
|
48
|
+
req.features.push('user-agent.' + req.userAgent);
|
|
49
|
+
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(req.userAgent)) {
|
|
50
|
+
req.features.push('os.mobile');
|
|
51
|
+
} else {
|
|
52
|
+
req.features.push('os.desktop');
|
|
41
53
|
}
|
|
42
|
-
if (req.headers['x-browser'] && req.headers['x-browser'].contains('social-browser')) {
|
|
43
|
-
req.features.push('browser.social');
|
|
44
|
-
req.features.push('browser.social.app');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (req.headers['user-agent']) {
|
|
48
|
-
req.userAgent = req.headers['user-agent'].toLowerCase();
|
|
49
|
-
req.features.push('user-agent.' + req.userAgent);
|
|
50
|
-
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(req.userAgent)) {
|
|
51
|
-
req.features.push('os.mobile');
|
|
52
|
-
} else {
|
|
53
|
-
req.features.push('os.desktop');
|
|
54
|
-
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
if (req.userAgent.contains('windows')) {
|
|
56
|
+
req.features.push('os.windows');
|
|
57
|
+
if (req.userAgent.contains('windows nt 5.1')) {
|
|
58
|
+
req.features.push('os.windowsxp');
|
|
59
|
+
} else if (req.userAgent.contains('windows nt 6.1')) {
|
|
60
|
+
req.features.push('os.windows7');
|
|
61
|
+
} else if (req.userAgent.contains('windows nt 6.2') || req.userAgent.contains('windows nt 6.3')) {
|
|
62
|
+
req.features.push('os.windows8');
|
|
63
|
+
} else if (req.userAgent.contains('windows nt 6.4') || req.userAgent.contains('windows nt 10')) {
|
|
64
|
+
req.features.push('os.windows10');
|
|
65
|
+
} else {
|
|
66
|
+
}
|
|
67
|
+
} else if (req.userAgent.contains('linux')) {
|
|
68
|
+
req.features.push('os.linux');
|
|
69
|
+
} else if (req.userAgent.contains('macintosh')) {
|
|
70
|
+
req.features.push('os.mac');
|
|
71
|
+
} else if (req.userAgent.contains('android')) {
|
|
72
|
+
req.features.push('os.android');
|
|
73
|
+
} else {
|
|
74
|
+
req.features.push('os.unknown');
|
|
75
|
+
}
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
77
|
+
if (req.userAgent.contains('edge')) {
|
|
78
|
+
req.features.push('browser.edge');
|
|
79
|
+
} else if (req.userAgent.contains('firefox')) {
|
|
80
|
+
req.features.push('browser.firefox');
|
|
81
|
+
} else if (req.userAgent.contains('opr')) {
|
|
82
|
+
req.features.push('browser.opera');
|
|
83
|
+
} else if (req.userAgent.contains('ucbrowser')) {
|
|
84
|
+
req.features.push('browser.ucbrowser');
|
|
85
|
+
} else if (req.userAgent.contains('bdbrowser') || req.userAgent.contains('baidu') || req.userAgent.contains('baidubrowser')) {
|
|
86
|
+
req.features.push('browser.baidu');
|
|
87
|
+
} else if (req.userAgent.contains('chromium')) {
|
|
88
|
+
req.features.push('browser.chromium');
|
|
89
|
+
} else if (req.userAgent.contains('chrome')) {
|
|
90
|
+
req.features.push('browser.chrome');
|
|
91
|
+
} else {
|
|
92
|
+
req.features.push('browser.unknown');
|
|
95
93
|
}
|
|
94
|
+
}
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
function ipInfo(session, callback) {
|
|
99
|
-
|
|
98
|
+
callback(session);
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
if (!____0.options.ipLookup) {
|
|
101
|
+
return session;
|
|
102
|
+
}
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
if (session.ip == '127.0.0.1' || session.ip == 'localhost') {
|
|
105
|
+
return session;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (session.$busy) {
|
|
109
|
+
return session;
|
|
110
|
+
}
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
____0.saveSession(session);
|
|
134
|
-
}, 1000 * 30);
|
|
135
|
-
})
|
|
136
|
-
.catch((err) => {
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
session = ____0.getSession(session);
|
|
139
|
-
session.$busy = !1;
|
|
140
|
-
____0.saveSession(session);
|
|
141
|
-
}, 1000 * 30);
|
|
112
|
+
session.$busy = !0;
|
|
113
|
+
____0.saveSession(session);
|
|
114
|
+
if (session.ip_list.length === 0 || !session.ip_list.some((info) => info.ip === session.ip)) {
|
|
115
|
+
____0
|
|
116
|
+
.fetch(`http://ip-api.com/json/${session.ip}`, {
|
|
117
|
+
method: 'get',
|
|
118
|
+
headers: { 'Content-Type': 'application/json' },
|
|
119
|
+
})
|
|
120
|
+
.then((res) => {
|
|
121
|
+
if (res.status == 200) {
|
|
122
|
+
return res.json();
|
|
123
|
+
} else {
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
.then((info) => {
|
|
127
|
+
____0.getSession(session, (session) => {
|
|
128
|
+
info.date = new Date();
|
|
129
|
+
info.ip = session.ip;
|
|
130
|
+
session.ip_list.unshift(info);
|
|
131
|
+
____0.saveSession(session);
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
____0.getSession(session, (session) => {
|
|
134
|
+
session.$busy = !1;
|
|
135
|
+
____0.saveSession(session);
|
|
142
136
|
});
|
|
143
|
-
|
|
137
|
+
}, 1000 * 30);
|
|
138
|
+
});
|
|
139
|
+
})
|
|
140
|
+
.catch((err) => {
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
____0.getSession(session, (session) => {
|
|
143
|
+
session.$busy = !1;
|
|
144
|
+
____0.saveSession(session);
|
|
145
|
+
});
|
|
146
|
+
}, 1000 * 30);
|
|
147
|
+
});
|
|
148
|
+
} else {
|
|
149
|
+
____0.getSession(session, (session) => {
|
|
150
|
+
session.$busy = !1;
|
|
151
|
+
____0.saveSession(session);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
AssignFeatures();
|
|
147
157
|
|
|
148
158
|
if (____0.security && session.user_id) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
____0.security.getUser(
|
|
160
|
+
{
|
|
161
|
+
id: session.user_id,
|
|
162
|
+
},
|
|
163
|
+
function (err, user) {
|
|
164
|
+
session.user = user;
|
|
165
|
+
if (session.user) {
|
|
166
|
+
if (!session.user.permissions) {
|
|
167
|
+
session.user.permissions = [];
|
|
168
|
+
}
|
|
169
|
+
req.features.push('login');
|
|
170
|
+
}
|
|
171
|
+
ipInfo(session, callback);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
164
174
|
} else {
|
|
165
|
-
|
|
175
|
+
ipInfo(session, callback);
|
|
166
176
|
}
|
|
177
|
+
});
|
|
167
178
|
};
|
package/lib/sessions.js
CHANGED
|
@@ -48,20 +48,42 @@ module.exports = function init(____0) {
|
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
sessions.list.forEach((s, i) => {
|
|
52
|
-
let online = new Date().getTime() - s.createdTime;
|
|
53
|
-
let timeout = 1000 * 60 * ____0.options.session.timeout;
|
|
54
|
-
if (online > timeout) {
|
|
55
|
-
sessions.list.splice(i, 1);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
51
|
if (____0.options.session.storage === 'mongodb') {
|
|
59
|
-
sessions
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
52
|
+
sessions.list.forEach((s, i) => {
|
|
53
|
+
if (!s) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (new Date().getTime() - s.createdTime > 1000 * 60 * ____0.options.session.timeout) {
|
|
57
|
+
sessions.list.splice(i, 1);
|
|
58
|
+
sessions.$collection.delete(s);
|
|
59
|
+
} else {
|
|
60
|
+
if (s.id) {
|
|
61
|
+
sessions.$collection.update(s, (err, result) => {
|
|
62
|
+
if (!err && result) {
|
|
63
|
+
sessions.list[i] = result.doc;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
sessions.$collection.insert(s, (err, doc) => {
|
|
68
|
+
if (!err && doc) {
|
|
69
|
+
sessions.list[i] = doc;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
});
|
|
64
75
|
} else {
|
|
76
|
+
sessions.list.forEach((s, i) => {
|
|
77
|
+
if (!s) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
let online = new Date().getTime() - s.createdTime;
|
|
81
|
+
let timeout = 1000 * 60 * ____0.options.session.timeout;
|
|
82
|
+
if (online > timeout) {
|
|
83
|
+
sessions.list.splice(i, 1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
65
87
|
____0.writeFile(sessions.path, JSON.stringify(sessions.list), () => {
|
|
66
88
|
callback(null, sessions.list);
|
|
67
89
|
console.log(' ... sessions Saved to ...' + sessions.path);
|
|
@@ -71,35 +93,68 @@ module.exports = function init(____0) {
|
|
|
71
93
|
return;
|
|
72
94
|
};
|
|
73
95
|
|
|
74
|
-
sessions.loadAll();
|
|
75
|
-
|
|
76
96
|
____0.getSession = sessions.attach = function (session, callback) {
|
|
77
97
|
callback = callback || function () {};
|
|
78
98
|
session.$exists = !1;
|
|
79
99
|
|
|
80
100
|
if (session.accessToken) {
|
|
81
101
|
sessions.list.forEach((s, i) => {
|
|
82
|
-
if (s.accessToken && s.accessToken == session.accessToken) {
|
|
102
|
+
if (s && s.accessToken && s.accessToken == session.accessToken) {
|
|
83
103
|
session.$exists = !0;
|
|
84
104
|
session.$index = i;
|
|
105
|
+
sessions.list[session.$index].requestesCount++;
|
|
85
106
|
}
|
|
86
107
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
if (!session.$exists) {
|
|
109
|
+
if (____0.options.session.storage === 'mongodb') {
|
|
110
|
+
sessions.$collection.find({ accessToken: session.accessToken }, (err, doc) => {
|
|
111
|
+
if (!err && doc) {
|
|
112
|
+
session.$exists = !0;
|
|
113
|
+
session = { ...session, ...doc };
|
|
114
|
+
session.requestesCount++;
|
|
115
|
+
session.$index = sessions.list.length;
|
|
116
|
+
sessions.list.push(session);
|
|
117
|
+
callback(sessions.list[session.$index]);
|
|
118
|
+
} else {
|
|
119
|
+
session.$new = !0;
|
|
120
|
+
session.lang = ____0.options.lang;
|
|
121
|
+
session.theme = ____0.options.theme;
|
|
122
|
+
session.data = [];
|
|
123
|
+
session.ip_list = [];
|
|
124
|
+
session.requestesCount = 1;
|
|
125
|
+
session.createdTime = new Date().getTime();
|
|
126
|
+
session.$index = sessions.list.length;
|
|
127
|
+
sessions.list.push(session);
|
|
128
|
+
callback(sessions.list[session.$index]);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
session.$new = !0;
|
|
133
|
+
session.lang = ____0.options.lang;
|
|
134
|
+
session.theme = ____0.options.theme;
|
|
135
|
+
session.data = [];
|
|
136
|
+
session.ip_list = session.ip_list || [];
|
|
137
|
+
session.requestesCount = 1;
|
|
138
|
+
session.createdTime = new Date().getTime();
|
|
139
|
+
session.$index = sessions.list.length;
|
|
140
|
+
sessions.list.push(session);
|
|
141
|
+
callback(sessions.list[session.$index]);
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
callback(sessions.list[session.$index]);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
90
147
|
session.$new = !0;
|
|
91
148
|
session.lang = ____0.options.lang;
|
|
92
149
|
session.theme = ____0.options.theme;
|
|
93
150
|
session.data = [];
|
|
94
|
-
session.
|
|
151
|
+
session.ip_list = session.ip_list || [];
|
|
95
152
|
session.requestesCount = 1;
|
|
96
153
|
session.createdTime = new Date().getTime();
|
|
97
154
|
session.$index = sessions.list.length;
|
|
98
155
|
sessions.list.push(session);
|
|
156
|
+
callback(sessions.list[session.$index]);
|
|
99
157
|
}
|
|
100
|
-
|
|
101
|
-
callback(sessions.list[session.$index]);
|
|
102
|
-
return sessions.list[session.$index];
|
|
103
158
|
};
|
|
104
159
|
|
|
105
160
|
____0.saveSession = sessions.save = function (session, callback) {
|
|
@@ -115,7 +170,7 @@ module.exports = function init(____0) {
|
|
|
115
170
|
if (session.$exists) {
|
|
116
171
|
return;
|
|
117
172
|
}
|
|
118
|
-
if (s.accessToken == session.accessToken) {
|
|
173
|
+
if (s && s.accessToken == session.accessToken) {
|
|
119
174
|
sessions.list[i] = { ...sessions.list[i], ...session };
|
|
120
175
|
session.$exists = !0;
|
|
121
176
|
session.$index = i;
|
|
@@ -153,15 +208,15 @@ module.exports = function init(____0) {
|
|
|
153
208
|
});
|
|
154
209
|
____0.on('[session][delete]', (session) => {
|
|
155
210
|
sessions.list.forEach((s, i) => {
|
|
156
|
-
if (s.accessToken == session.accessToken) {
|
|
211
|
+
if (s && s.accessToken == session.accessToken) {
|
|
157
212
|
sessions.list.splice(i, 1);
|
|
158
213
|
}
|
|
159
214
|
});
|
|
160
215
|
});
|
|
161
216
|
____0.on('[session][user][update]', (user) => {
|
|
162
|
-
sessions.list.forEach((s) => {
|
|
163
|
-
if (s.user && s.user.id == user.id) {
|
|
164
|
-
|
|
217
|
+
sessions.list.forEach((s, i) => {
|
|
218
|
+
if (s && s.user && s.user.id == user.id) {
|
|
219
|
+
sessions.list[i].user = user;
|
|
165
220
|
}
|
|
166
221
|
});
|
|
167
222
|
});
|
|
@@ -179,6 +234,13 @@ module.exports = function init(____0) {
|
|
|
179
234
|
});
|
|
180
235
|
});
|
|
181
236
|
|
|
237
|
+
____0.onPOST('x-api/session', (req, res) => {
|
|
238
|
+
res.json({
|
|
239
|
+
done: !0,
|
|
240
|
+
session: req.session,
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
182
244
|
____0.onPOST('x-api/sessions', (req, res) => {
|
|
183
245
|
res.json({
|
|
184
246
|
done: !0,
|
|
@@ -203,5 +265,8 @@ module.exports = function init(____0) {
|
|
|
203
265
|
});
|
|
204
266
|
});
|
|
205
267
|
|
|
268
|
+
if (!____0.options.session.storage === 'mongodb') {
|
|
269
|
+
sessions.loadAll();
|
|
270
|
+
}
|
|
206
271
|
return sessions;
|
|
207
272
|
};
|