total5 0.0.1-9 → 0.0.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/api.js +18 -10
- package/bin/flow5 +142 -0
- package/bin/total5 +166 -905
- package/builders.js +90 -35
- package/changelog.txt +3 -1
- package/cluster.js +1 -1
- package/cms.js +185 -51
- package/controller.js +233 -70
- package/cron.js +1 -1
- package/debug.js +12 -5
- package/edit.js +26 -33
- package/filestorage.js +38 -17
- package/flow-flowstream.js +199 -68
- package/flow.js +16 -10
- package/flowstream.js +4 -3
- package/global.js +84 -1
- package/htmlparser.js +41 -29
- package/http.js +3 -1
- package/image.js +4 -0
- package/images.js +1 -1
- package/index.js +246 -117
- package/jsonschema.js +21 -17
- package/macros.js +222 -0
- package/mail.js +11 -27
- package/markdown.js +21 -11
- package/minificators.js +1 -1
- package/nosql-querybuilder.js +4 -0
- package/nosql.js +8 -0
- package/openclient.js +1 -1
- package/package.json +4 -3
- package/pause.html +1 -1
- package/release.js +1 -1
- package/routing.js +118 -35
- package/sourcemap.js +6 -3
- package/test.js +9 -2
- package/tms.js +11 -14
- package/uibuilder.js +59 -23
- package/utils.js +147 -102
- package/viewengine.js +19 -8
- package/websocket.js +10 -6
- package/503.html +0 -65
- package/CONTRIBUTING.md +0 -55
- package/helpers/index.js +0 -32
- package/templates.json +0 -74
- package/tests/bundles/index.js +0 -25
- package/tests/cron.js +0 -0
- package/tests/htmlparser.js +0 -0
- package/tests/minifactors.js +0 -17
- package/tests/nosql.js +0 -18
- package/tests/proxy/index.js +0 -21
- package/tests/routing/index.js +0 -27
- package/tests/schemas.js +0 -17
- package/tests/server/index.js +0 -24
- package/tests/staticfiles/index.js +0 -24
- package/tests/utils.js +0 -17
- package/tmsclient.js +0 -125
- package/todo.txt +0 -11
- package/tools/beta.sh +0 -6
- package/tools/release.sh +0 -6
package/utils.js
CHANGED
|
@@ -41,7 +41,7 @@ const REG_TAGS = /<\/?[^>]+(>|$)/g;
|
|
|
41
41
|
const REG_UA = /[a-z]+/gi;
|
|
42
42
|
const REG_XML = /\w+=".*?"/g;
|
|
43
43
|
const REG_DECODE = /&#?[a-z0-9]+;/g;
|
|
44
|
-
const REG_ARGS = /\{{1,2}[a-z0-9_
|
|
44
|
+
const REG_ARGS = /\{{1,2}[a-z0-9_$.-\s]+\}{1,2}/gi;
|
|
45
45
|
const REG_INTEGER = /(^-|\s-)?[0-9]+/g;
|
|
46
46
|
const REG_FLOAT = /(^-|\s-)?[0-9.,]+/g;
|
|
47
47
|
const REG_TERMINAL = /[\w\S]+/g;
|
|
@@ -51,6 +51,8 @@ const REG_KEYWORD2 = /\n/g;
|
|
|
51
51
|
const REG_KEYWORD3 = /\W|_/g;
|
|
52
52
|
const REG_BASE = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
|
|
53
53
|
const REG_BASE2 = /^|,([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
|
|
54
|
+
const REG_NUMBER = /^[0-9,.]$/;
|
|
55
|
+
const REG_WIN = /\\/g;
|
|
54
56
|
|
|
55
57
|
const NEWLINE = '\r\n';
|
|
56
58
|
const DIACRITICSMAP = {};
|
|
@@ -71,6 +73,7 @@ const REG_TIME = /am|pm/i;
|
|
|
71
73
|
const REG_XMLKEY = /\[|\]|:|\.|_/g;
|
|
72
74
|
const REG_HEADERPARSER = /(name|filename)=".*?"|content-type:\s[a-z0-9-./+]+/ig;
|
|
73
75
|
const HEADEREND = Buffer.from('\r\n\r\n', 'ascii');
|
|
76
|
+
const JSCHEMAS_NULLABLE = { json: 1, base64: 1, guid: 1, datauri: 1, uid: 1, string2: 1 };
|
|
74
77
|
|
|
75
78
|
exports.MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
76
79
|
exports.DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
@@ -85,6 +88,26 @@ const REG_UTF8 = /[\u3400-\u9FBF]/;
|
|
|
85
88
|
|
|
86
89
|
exports.success = { success: true };
|
|
87
90
|
exports.noop = function() {};
|
|
91
|
+
exports.toError = function(err) {
|
|
92
|
+
|
|
93
|
+
if (err instanceof Error)
|
|
94
|
+
return err;
|
|
95
|
+
|
|
96
|
+
if (err instanceof F.TBuilders.ErrorBuilder)
|
|
97
|
+
return new Error(err.toString());
|
|
98
|
+
|
|
99
|
+
switch (typeof(err)) {
|
|
100
|
+
case 'string':
|
|
101
|
+
case 'number':
|
|
102
|
+
return new Error(err + '');
|
|
103
|
+
default:
|
|
104
|
+
if (err instanceof Array)
|
|
105
|
+
err = err[0];
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return new Error((err ? (err.error || err.err || err.name) : '') || 'Unknown error');
|
|
110
|
+
};
|
|
88
111
|
|
|
89
112
|
exports.parseConfig = function(value) {
|
|
90
113
|
|
|
@@ -194,6 +217,12 @@ exports.parseConfig = function(value) {
|
|
|
194
217
|
generated.push(key);
|
|
195
218
|
break;
|
|
196
219
|
default:
|
|
220
|
+
|
|
221
|
+
if (val === 'true' || val === 'false')
|
|
222
|
+
val = val === 'true';
|
|
223
|
+
else if (REG_NUMBER.test(val))
|
|
224
|
+
val = val.parseFloat();
|
|
225
|
+
|
|
197
226
|
cfg[key] = val;
|
|
198
227
|
break;
|
|
199
228
|
}
|
|
@@ -287,9 +316,10 @@ var CONTENTTYPES = {
|
|
|
287
316
|
ico: 'image/x-icon',
|
|
288
317
|
ics: 'text/calendar',
|
|
289
318
|
ifb: 'text/calendar',
|
|
290
|
-
|
|
291
|
-
|
|
319
|
+
ipynb: 'application/x-ipynb+json',
|
|
320
|
+
ijsnb: 'application/x-ijsnb+json',
|
|
292
321
|
jpg: 'image/jpeg',
|
|
322
|
+
jpeg: 'image/jpeg',
|
|
293
323
|
js: 'text/javascript',
|
|
294
324
|
json: 'application/json',
|
|
295
325
|
ui: 'application/json', // UI builder
|
|
@@ -685,8 +715,8 @@ function _request(opt, callback) {
|
|
|
685
715
|
if (options.resolve && (opt.unixsocket || (uri.hostname === 'localhost' || uri.hostname.charCodeAt(0) < 64)))
|
|
686
716
|
options.resolve = false;
|
|
687
717
|
|
|
688
|
-
if (!opt.unixsocket &&
|
|
689
|
-
proxy = parseProxy(
|
|
718
|
+
if (!opt.unixsocket && F.config.$proxyrequest && !proxy && !PROXYBLACKLIST[uri.hostname])
|
|
719
|
+
proxy = parseProxy(F.config.$proxyrequest);
|
|
690
720
|
|
|
691
721
|
if (!opt.unixsocket && proxy && (uri.hostname === 'localhost' || uri.hostname === '127.0.0.1'))
|
|
692
722
|
proxy = null;
|
|
@@ -1739,42 +1769,40 @@ exports.distance = function(lat1, lon1, lat2, lon2) {
|
|
|
1739
1769
|
return (R * c).floor(3);
|
|
1740
1770
|
};
|
|
1741
1771
|
|
|
1742
|
-
function ls(path, callback, advanced, filter) {
|
|
1772
|
+
function ls(path, callback, advanced, filter, unified) {
|
|
1773
|
+
|
|
1743
1774
|
var filelist = new FileList();
|
|
1744
1775
|
var tmp;
|
|
1745
1776
|
|
|
1777
|
+
filelist.unified = unified == true;
|
|
1746
1778
|
filelist.advanced = advanced;
|
|
1747
1779
|
filelist.onComplete = callback;
|
|
1748
1780
|
|
|
1749
1781
|
if (typeof(filter) === 'string') {
|
|
1750
1782
|
tmp = filter.toLowerCase();
|
|
1751
|
-
filelist.onFilter =
|
|
1752
|
-
return is ? true : filename.toLowerCase().indexOf(tmp) !== -1;
|
|
1753
|
-
};
|
|
1783
|
+
filelist.onFilter = (filename, is) => is ? true : filename.toLowerCase().indexOf(tmp) !== -1;
|
|
1754
1784
|
} else if (filter && filter.test) {
|
|
1755
1785
|
// regexp
|
|
1756
1786
|
tmp = filter;
|
|
1757
|
-
filelist.onFilter =
|
|
1758
|
-
return is ? true : tmp.test(filename);
|
|
1759
|
-
};
|
|
1787
|
+
filelist.onFilter = (filename, is) => is ? true : tmp.test(filename);
|
|
1760
1788
|
} else
|
|
1761
1789
|
filelist.onFilter = filter || null;
|
|
1762
1790
|
|
|
1763
1791
|
filelist.walk(path);
|
|
1764
1792
|
}
|
|
1765
1793
|
|
|
1766
|
-
exports.ls = function(path, callback, filter) {
|
|
1794
|
+
exports.ls = function(path, callback, filter, unified) {
|
|
1767
1795
|
if (callback)
|
|
1768
|
-
ls(path, callback, false, filter);
|
|
1796
|
+
ls(path, callback, false, filter, unified);
|
|
1769
1797
|
else
|
|
1770
|
-
return new Promise(resolve => ls(path, (files, dirs) => resolve({ directories: dirs, files: files }), false, filter));
|
|
1798
|
+
return new Promise(resolve => ls(path, (files, dirs) => resolve({ directories: dirs, files: files }), false, filter, unified));
|
|
1771
1799
|
};
|
|
1772
1800
|
|
|
1773
|
-
exports.ls2 = function(path, callback, filter) {
|
|
1801
|
+
exports.ls2 = function(path, callback, filter, unified) {
|
|
1774
1802
|
if (callback)
|
|
1775
|
-
ls(path, callback, true, filter);
|
|
1803
|
+
ls(path, callback, true, filter, unified);
|
|
1776
1804
|
else
|
|
1777
|
-
return new Promise(resolve => ls(path, (files, dirs) => resolve({ directories: dirs, files: files }), true, filter));
|
|
1805
|
+
return new Promise(resolve => ls(path, (files, dirs) => resolve({ directories: dirs, files: files }), true, filter, unified));
|
|
1778
1806
|
};
|
|
1779
1807
|
|
|
1780
1808
|
DP.setTimeZone = function(timezone) {
|
|
@@ -2200,7 +2228,16 @@ SP.hash = function(type, salt) {
|
|
|
2200
2228
|
}
|
|
2201
2229
|
};
|
|
2202
2230
|
|
|
2203
|
-
SP.sign = function(key) {
|
|
2231
|
+
SP.sign = function(key, check) {
|
|
2232
|
+
|
|
2233
|
+
if (check) {
|
|
2234
|
+
let index = this.lastIndexOf('-');
|
|
2235
|
+
if (index === -1)
|
|
2236
|
+
return null;
|
|
2237
|
+
var id = this.substring(0, index);
|
|
2238
|
+
return id.sign(key) === this ? id : null;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2204
2241
|
return this + '-' + (string_hash(this + (key || '')) >>> 0).toString(36);
|
|
2205
2242
|
};
|
|
2206
2243
|
|
|
@@ -2378,6 +2415,10 @@ SP.streamer = function(beg, end, callback, skip) {
|
|
|
2378
2415
|
|
|
2379
2416
|
};
|
|
2380
2417
|
|
|
2418
|
+
SP.parseXML2 = function() {
|
|
2419
|
+
return require('./htmlparser').parseHTML(this, false, null, true);
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2381
2422
|
SP.parseXML = function(replace) {
|
|
2382
2423
|
|
|
2383
2424
|
var xml = this;
|
|
@@ -2542,13 +2583,13 @@ SP.parseEncoded = function() {
|
|
|
2542
2583
|
decodek = false;
|
|
2543
2584
|
decodev = false;
|
|
2544
2585
|
|
|
2545
|
-
if ((count++) >=
|
|
2586
|
+
if ((count++) >= F.config.$httpmaxkeys)
|
|
2546
2587
|
break;
|
|
2547
2588
|
|
|
2548
2589
|
} else {
|
|
2549
2590
|
|
|
2550
2591
|
if (n === 61) {
|
|
2551
|
-
if ((i - pos) >
|
|
2592
|
+
if ((i - pos) > F.config.$httpmaxkey)
|
|
2552
2593
|
key = '';
|
|
2553
2594
|
else {
|
|
2554
2595
|
if (pos < i)
|
|
@@ -3118,7 +3159,7 @@ SP.parseDateExpiration = function() {
|
|
|
3118
3159
|
};
|
|
3119
3160
|
|
|
3120
3161
|
var configurereplace = function(text) {
|
|
3121
|
-
var val =
|
|
3162
|
+
var val = F.config[text.substring(1, text.length - 1)];
|
|
3122
3163
|
return val == null ? '' : val;
|
|
3123
3164
|
};
|
|
3124
3165
|
|
|
@@ -3184,7 +3225,7 @@ SP.parseConfig = function(def, onerr) {
|
|
|
3184
3225
|
obj[name] = (/true|on|1|enabled/i).test(value);
|
|
3185
3226
|
break;
|
|
3186
3227
|
case 'config':
|
|
3187
|
-
obj[name] =
|
|
3228
|
+
obj[name] = F.config[value];
|
|
3188
3229
|
break;
|
|
3189
3230
|
case 'eval':
|
|
3190
3231
|
case 'object':
|
|
@@ -3238,7 +3279,7 @@ SP.decrypt_uid = function(key) {
|
|
|
3238
3279
|
return exports.decrypt_uid(this, key);
|
|
3239
3280
|
};
|
|
3240
3281
|
|
|
3241
|
-
SP.safehtml = function() {
|
|
3282
|
+
SP.encode = SP.safehtml = function() {
|
|
3242
3283
|
var output = '';
|
|
3243
3284
|
for (var i = 0, length = this.length; i < length; i++) {
|
|
3244
3285
|
var c = this[i];
|
|
@@ -3280,6 +3321,7 @@ SP.arg = SP.args = function(obj, encode, def) {
|
|
|
3280
3321
|
def = encode;
|
|
3281
3322
|
var isfn = typeof(encode) === 'function';
|
|
3282
3323
|
return this.replace(REG_ARGS, function(text) {
|
|
3324
|
+
|
|
3283
3325
|
// Is double bracket?
|
|
3284
3326
|
var l = text[1] === '{' ? 2 : 1;
|
|
3285
3327
|
var key = text.substring(l, text.length - l).trim();
|
|
@@ -3425,6 +3467,18 @@ SP.isUID = function() {
|
|
|
3425
3467
|
return false;
|
|
3426
3468
|
};
|
|
3427
3469
|
|
|
3470
|
+
// Remove the trailing slash
|
|
3471
|
+
SP.tslash = function() {
|
|
3472
|
+
var t = this;
|
|
3473
|
+
|
|
3474
|
+
for (var i = t.length - 1; i > 0; i--) {
|
|
3475
|
+
if (t[i] !== '/' || i === 1)
|
|
3476
|
+
return t.substring(0, i + 1);
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
return t;
|
|
3480
|
+
};
|
|
3481
|
+
|
|
3428
3482
|
SP.parseUID = function() {
|
|
3429
3483
|
var self = this;
|
|
3430
3484
|
var obj = {};
|
|
@@ -3518,7 +3572,7 @@ SP.parseUID = function() {
|
|
|
3518
3572
|
return obj;
|
|
3519
3573
|
};
|
|
3520
3574
|
|
|
3521
|
-
|
|
3575
|
+
SP.parseEnv = function() {
|
|
3522
3576
|
|
|
3523
3577
|
var arr = this.split(REG_ENVLINES);
|
|
3524
3578
|
var obj = {};
|
|
@@ -3760,7 +3814,7 @@ SP.encrypt = function(key, isUnique, secret) {
|
|
|
3760
3814
|
for (var i = 0; i < str.length; i++)
|
|
3761
3815
|
sum += str.charCodeAt(i);
|
|
3762
3816
|
|
|
3763
|
-
return (sum + checksum((secret ||
|
|
3817
|
+
return (sum + checksum((secret || F.config.secret) + key)) + '-' + str;
|
|
3764
3818
|
};
|
|
3765
3819
|
|
|
3766
3820
|
SP.decrypt = function(key, secret) {
|
|
@@ -3774,7 +3828,7 @@ SP.decrypt = function(key, secret) {
|
|
|
3774
3828
|
return null;
|
|
3775
3829
|
|
|
3776
3830
|
var hash = this.substring(index + 1);
|
|
3777
|
-
var sum = checksum((secret ||
|
|
3831
|
+
var sum = checksum((secret || F.config.secret) + key);
|
|
3778
3832
|
for (var i = 0; i < hash.length; i++)
|
|
3779
3833
|
sum += hash.charCodeAt(i);
|
|
3780
3834
|
|
|
@@ -3892,7 +3946,7 @@ exports.encrypt_uid = function(val, key) {
|
|
|
3892
3946
|
var sum = 0;
|
|
3893
3947
|
|
|
3894
3948
|
if (!key)
|
|
3895
|
-
key =
|
|
3949
|
+
key = F.config.secret;
|
|
3896
3950
|
|
|
3897
3951
|
val = val + '';
|
|
3898
3952
|
|
|
@@ -3918,7 +3972,7 @@ exports.decrypt_uid = function(val, key) {
|
|
|
3918
3972
|
exports.encrypt_crypto = function(type, key, value) {
|
|
3919
3973
|
if (!F.temporary.keys[key])
|
|
3920
3974
|
F.temporary.keys[key] = Buffer.from(key);
|
|
3921
|
-
var cipher = F.Crypto.createCipheriv(type, F.temporary.keys[key],
|
|
3975
|
+
var cipher = F.Crypto.createCipheriv(type, F.temporary.keys[key], F.config.$cryptoiv);
|
|
3922
3976
|
CONCAT[0] = cipher.update(value);
|
|
3923
3977
|
CONCAT[1] = cipher.final();
|
|
3924
3978
|
return Buffer.concat(CONCAT);
|
|
@@ -3927,7 +3981,7 @@ exports.encrypt_crypto = function(type, key, value) {
|
|
|
3927
3981
|
exports.decrypt_crypto = function(type, key, value) {
|
|
3928
3982
|
if (!F.temporary.keys[key])
|
|
3929
3983
|
F.temporary.keys[key] = Buffer.from(key);
|
|
3930
|
-
var decipher = F.Crypto.createDecipheriv(type, F.temporary.keys[key],
|
|
3984
|
+
var decipher = F.Crypto.createDecipheriv(type, F.temporary.keys[key], F.config.$cryptoiv);
|
|
3931
3985
|
try {
|
|
3932
3986
|
CONCAT[0] = decipher.update(value);
|
|
3933
3987
|
CONCAT[1] = decipher.final();
|
|
@@ -4514,7 +4568,7 @@ AP.findAll = function(cb, value) {
|
|
|
4514
4568
|
};
|
|
4515
4569
|
|
|
4516
4570
|
AP.findValue = function(cb, value, path, def) {
|
|
4517
|
-
var index = this.
|
|
4571
|
+
var index = this.TfindIndex(cb, value);
|
|
4518
4572
|
if (index !== -1) {
|
|
4519
4573
|
var item = this[index][path];
|
|
4520
4574
|
return item == null ? def : item;
|
|
@@ -4524,13 +4578,14 @@ AP.findValue = function(cb, value, path, def) {
|
|
|
4524
4578
|
|
|
4525
4579
|
AP.findItem = function(cb, value) {
|
|
4526
4580
|
var self = this;
|
|
4527
|
-
var index = self.
|
|
4581
|
+
var index = self.TfindIndex(cb, value);
|
|
4528
4582
|
if (index === -1)
|
|
4529
4583
|
return null;
|
|
4530
4584
|
return self[index];
|
|
4531
4585
|
};
|
|
4532
4586
|
|
|
4533
|
-
|
|
4587
|
+
// TfindIndex due to other NPM dependencies
|
|
4588
|
+
AP.TfindIndex = AP.findIndex = function(cb, value) {
|
|
4534
4589
|
|
|
4535
4590
|
var self = this;
|
|
4536
4591
|
var isFN = typeof(cb) === 'function';
|
|
@@ -4647,6 +4702,8 @@ AP.async = function(thread, callback, tmp) {
|
|
|
4647
4702
|
thread = 1;
|
|
4648
4703
|
} else if (thread === undefined)
|
|
4649
4704
|
thread = 1;
|
|
4705
|
+
else if (thread > self.length)
|
|
4706
|
+
thread = self.length;
|
|
4650
4707
|
|
|
4651
4708
|
if (!tmp) {
|
|
4652
4709
|
tmp = {};
|
|
@@ -4754,6 +4811,7 @@ function FileList() {
|
|
|
4754
4811
|
this.onComplete = null;
|
|
4755
4812
|
this.onFilter = null;
|
|
4756
4813
|
this.advanced = false;
|
|
4814
|
+
this.unified = false;
|
|
4757
4815
|
}
|
|
4758
4816
|
|
|
4759
4817
|
const FLP = FileList.prototype;
|
|
@@ -4795,19 +4853,23 @@ FLP.stat = function(path) {
|
|
|
4795
4853
|
if (err)
|
|
4796
4854
|
return self.next();
|
|
4797
4855
|
|
|
4856
|
+
var cleaned = self.unified && F.isWindows ? path.replace(REG_WIN, '/') : path;
|
|
4857
|
+
var path2 = path;
|
|
4858
|
+
|
|
4798
4859
|
if (stats.isDirectory()) {
|
|
4799
4860
|
path = self.clean(path);
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4861
|
+
cleaned = self.unified && F.isWindows ? path.replace(REG_WIN, '/') : path;
|
|
4862
|
+
|
|
4863
|
+
if (!self.onFilter || self.onFilter(cleaned, true)) {
|
|
4864
|
+
self.directory.push(cleaned);
|
|
4865
|
+
self.pendingDirectory.push(path2);
|
|
4803
4866
|
}
|
|
4804
|
-
} else if (!self.onFilter || self.onFilter(
|
|
4805
|
-
self.file.push(self.advanced ? { filename:
|
|
4867
|
+
} else if (!self.onFilter || self.onFilter(cleaned, false))
|
|
4868
|
+
self.file.push(self.advanced ? { filename: cleaned, stats: stats } : cleaned);
|
|
4806
4869
|
|
|
4807
4870
|
self.next();
|
|
4808
4871
|
});
|
|
4809
4872
|
};
|
|
4810
|
-
|
|
4811
4873
|
FLP.clean = function(path) {
|
|
4812
4874
|
return path[path.length - 1] === F.Path.sep ? path : path + F.Path.sep;
|
|
4813
4875
|
};
|
|
@@ -5870,10 +5932,10 @@ exports.connect = function(opt, callback) {
|
|
|
5870
5932
|
meta.socket1.on('clientError', error);
|
|
5871
5933
|
};
|
|
5872
5934
|
|
|
5873
|
-
|
|
5935
|
+
SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
5874
5936
|
|
|
5875
5937
|
var obj = {};
|
|
5876
|
-
var p = (url ||
|
|
5938
|
+
var p = (url || F.config.url || 'https://schemas.totaljs.com');
|
|
5877
5939
|
|
|
5878
5940
|
if (p[p.length - 1] !== '/')
|
|
5879
5941
|
p += '/';
|
|
@@ -5971,7 +6033,10 @@ String.prototype.toJSONSchema = String.prototype.parseSchema = function(name, ur
|
|
|
5971
6033
|
type = 'object';
|
|
5972
6034
|
}
|
|
5973
6035
|
|
|
5974
|
-
|
|
6036
|
+
var ltype = type.toLowerCase();
|
|
6037
|
+
|
|
6038
|
+
switch (ltype) {
|
|
6039
|
+
case 'string2':
|
|
5975
6040
|
case 'string':
|
|
5976
6041
|
case 'uid':
|
|
5977
6042
|
case 'guid':
|
|
@@ -5989,19 +6054,21 @@ String.prototype.toJSONSchema = String.prototype.parseSchema = function(name, ur
|
|
|
5989
6054
|
case 'color':
|
|
5990
6055
|
case 'icon':
|
|
5991
6056
|
case 'base64':
|
|
6057
|
+
case 'datauri':
|
|
5992
6058
|
case 'safestring':
|
|
5993
6059
|
case 'search':
|
|
5994
6060
|
case 'text':
|
|
5995
6061
|
tmp = {};
|
|
5996
6062
|
if (isarr) {
|
|
5997
6063
|
tmp.type = 'array';
|
|
5998
|
-
tmp.items = { type: 'string', subtype:
|
|
6064
|
+
tmp.items = { type: 'string', subtype: ltype === 'text' ? undefined : ltype, nullable: JSCHEMAS_NULLABLE[ltype] };
|
|
5999
6065
|
if (size)
|
|
6000
6066
|
tmp.items.maxLength = size;
|
|
6001
6067
|
} else {
|
|
6002
6068
|
tmp.type = 'string';
|
|
6003
|
-
|
|
6004
|
-
|
|
6069
|
+
tmp.nullable = JSCHEMAS_NULLABLE[ltype];
|
|
6070
|
+
if (ltype !== tmp.type)
|
|
6071
|
+
tmp.subtype = ltype;
|
|
6005
6072
|
if (size)
|
|
6006
6073
|
tmp.maxLength = size;
|
|
6007
6074
|
}
|
|
@@ -6021,11 +6088,11 @@ String.prototype.toJSONSchema = String.prototype.parseSchema = function(name, ur
|
|
|
6021
6088
|
tmp = {};
|
|
6022
6089
|
if (isarr) {
|
|
6023
6090
|
tmp.type = 'array';
|
|
6024
|
-
tmp.items = { type: 'number', subtype: type === 'number' ? undefined :
|
|
6091
|
+
tmp.items = { type: 'number', subtype: type === 'number' ? undefined : ltype };
|
|
6025
6092
|
} else {
|
|
6026
6093
|
tmp.type = 'number';
|
|
6027
|
-
if (
|
|
6028
|
-
tmp.subtype =
|
|
6094
|
+
if (ltype !== 'number')
|
|
6095
|
+
tmp.subtype = ltype;
|
|
6029
6096
|
}
|
|
6030
6097
|
|
|
6031
6098
|
break;
|
|
@@ -6250,7 +6317,8 @@ exports.parseURI2 = function(url) {
|
|
|
6250
6317
|
if (index != -1)
|
|
6251
6318
|
url = url.replace(REG_TRAVELSE, '');
|
|
6252
6319
|
|
|
6253
|
-
|
|
6320
|
+
let key = url.toLowerCase();
|
|
6321
|
+
return { key: key, cache: key, pathname: url, search: search, file: index != -1, ext: index == -1 ? '' : url.substring(index + 1), split: split };
|
|
6254
6322
|
};
|
|
6255
6323
|
|
|
6256
6324
|
function destroyStreamopen() {
|
|
@@ -6265,9 +6333,10 @@ exports.destroystream = function(stream) {
|
|
|
6265
6333
|
|
|
6266
6334
|
if (stream instanceof F.Fs.ReadStream) {
|
|
6267
6335
|
stream.destroy();
|
|
6268
|
-
typeof(stream.close) === 'function'
|
|
6269
|
-
|
|
6270
|
-
|
|
6336
|
+
if (typeof(stream.close) === 'function')
|
|
6337
|
+
stream.on('open', destroyStreamopen);
|
|
6338
|
+
} else if (stream instanceof F.Stream && typeof(stream.destroy) === 'function')
|
|
6339
|
+
stream.destroy();
|
|
6271
6340
|
|
|
6272
6341
|
if (stream.$totalfd) {
|
|
6273
6342
|
F.Fs.close(stream.$totalfd, NOOP);
|
|
@@ -6298,7 +6367,8 @@ exports.onfinished = function(stream, fn) {
|
|
|
6298
6367
|
stream.$onFinishedQueue = fn;
|
|
6299
6368
|
|
|
6300
6369
|
var callback = function() {
|
|
6301
|
-
|
|
6370
|
+
if (!stream.$onFinished)
|
|
6371
|
+
stream.$onFinished = true;
|
|
6302
6372
|
if (stream.$onFinishedQueue instanceof Array) {
|
|
6303
6373
|
while (stream.$onFinishedQueue.length)
|
|
6304
6374
|
stream.$onFinishedQueue.shift()();
|
|
@@ -6309,36 +6379,31 @@ exports.onfinished = function(stream, fn) {
|
|
|
6309
6379
|
}
|
|
6310
6380
|
};
|
|
6311
6381
|
|
|
6312
|
-
if (
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
stream.socket.prependListener('close', callback);
|
|
6322
|
-
} else {
|
|
6323
|
-
stream.socket.on('error', callback);
|
|
6324
|
-
stream.socket.on('close', callback);
|
|
6325
|
-
}
|
|
6382
|
+
if (stream.socket) {
|
|
6383
|
+
if (!stream.socket.$totalstream) {
|
|
6384
|
+
stream.socket.$totalstream = stream;
|
|
6385
|
+
if (stream.socket.prependListener) {
|
|
6386
|
+
stream.socket.prependListener('error', callback);
|
|
6387
|
+
stream.socket.prependListener('close', callback);
|
|
6388
|
+
} else {
|
|
6389
|
+
stream.socket.on('error', callback);
|
|
6390
|
+
stream.socket.on('close', callback);
|
|
6326
6391
|
}
|
|
6327
6392
|
}
|
|
6393
|
+
}
|
|
6328
6394
|
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
}
|
|
6395
|
+
if (stream.prependListener) {
|
|
6396
|
+
stream.prependListener('error', callback);
|
|
6397
|
+
stream.prependListener('end', callback);
|
|
6398
|
+
stream.prependListener('close', callback);
|
|
6399
|
+
stream.prependListener('aborted', callback);
|
|
6400
|
+
stream.prependListener('finish', callback);
|
|
6401
|
+
} else {
|
|
6402
|
+
stream.on('error', callback);
|
|
6403
|
+
stream.on('end', callback);
|
|
6404
|
+
stream.on('close', callback);
|
|
6405
|
+
stream.on('aborted', callback);
|
|
6406
|
+
stream.on('finish', callback);
|
|
6342
6407
|
}
|
|
6343
6408
|
};
|
|
6344
6409
|
|
|
@@ -6351,7 +6416,7 @@ exports.uidr = function() {
|
|
|
6351
6416
|
var c;
|
|
6352
6417
|
|
|
6353
6418
|
if (i === 9) {
|
|
6354
|
-
c = F.uidc;
|
|
6419
|
+
c = F.internal.uidc;
|
|
6355
6420
|
} else {
|
|
6356
6421
|
let index = Math.floor(Math.random() * RANDOM_TEXT.length);
|
|
6357
6422
|
c = RANDOM_TEXT[index];
|
|
@@ -6364,24 +6429,4 @@ exports.uidr = function() {
|
|
|
6364
6429
|
}
|
|
6365
6430
|
|
|
6366
6431
|
return builder + RANDOM_STRING[sum] + 'r'; // "r" version
|
|
6367
|
-
};
|
|
6368
|
-
|
|
6369
|
-
function isFinished(stream) {
|
|
6370
|
-
|
|
6371
|
-
// Response & Request
|
|
6372
|
-
if (stream.socket) {
|
|
6373
|
-
if (stream.writable && (!stream.socket._writableState || stream.socket._writableState.finished || stream.socket._writableState.destroyed))
|
|
6374
|
-
return true;
|
|
6375
|
-
if (stream.readable && (!stream.socket._readableState|| stream.socket._writableState.ended || stream.socket._readableState.destroyed))
|
|
6376
|
-
return true;
|
|
6377
|
-
return false;
|
|
6378
|
-
}
|
|
6379
|
-
|
|
6380
|
-
if (stream._readableState && (stream._readableState.ended || stream._readableState.destroyed))
|
|
6381
|
-
return true;
|
|
6382
|
-
|
|
6383
|
-
if (stream._writableState && (stream._writableState.finished || stream._writableState.destroyed))
|
|
6384
|
-
return true;
|
|
6385
|
-
|
|
6386
|
-
return false;
|
|
6387
|
-
}
|
|
6432
|
+
};
|
package/viewengine.js
CHANGED
|
@@ -277,7 +277,7 @@ function parseplus(builder) {
|
|
|
277
277
|
return c !== '!' && c !== '?' && c !== '+' && c !== '.' && c !== ':';
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
function prepare(command,
|
|
280
|
+
function prepare(command, dcommand, functions) {
|
|
281
281
|
|
|
282
282
|
var a = command.indexOf('.');
|
|
283
283
|
var b = command.indexOf('(');
|
|
@@ -301,10 +301,10 @@ function prepare(command, dynamicCommand, functions) {
|
|
|
301
301
|
index = command.length;
|
|
302
302
|
|
|
303
303
|
var name = command.substring(0, index);
|
|
304
|
-
if (name ===
|
|
304
|
+
if (name === dcommand)
|
|
305
305
|
return 'self.safehtml(' + command + ', 1)';
|
|
306
306
|
|
|
307
|
-
if (name[0] === '!' && name.substring(1) ===
|
|
307
|
+
if (name[0] === '!' && name.substring(1) === dcommand)
|
|
308
308
|
return 'self.safehtml(' + command.substring(1) + ')';
|
|
309
309
|
|
|
310
310
|
switch (name) {
|
|
@@ -328,7 +328,7 @@ function prepare(command, dynamicCommand, functions) {
|
|
|
328
328
|
return 'self.csrf()';
|
|
329
329
|
|
|
330
330
|
case 'root':
|
|
331
|
-
var r =
|
|
331
|
+
var r = F.config.$root;
|
|
332
332
|
return '\'' + (r ? r.substring(0, r.length - 1) : r) + '\'';
|
|
333
333
|
|
|
334
334
|
case 'CONF':
|
|
@@ -391,13 +391,13 @@ function prepare(command, dynamicCommand, functions) {
|
|
|
391
391
|
return command.indexOf('(') === -1 ? '((repository[\'' + command + '\'] || \'\') + \'\').safehtml()' : 'self.' + command;
|
|
392
392
|
|
|
393
393
|
case 'title2':
|
|
394
|
-
return 'self
|
|
394
|
+
return 'self.' + command;
|
|
395
395
|
|
|
396
396
|
case '!title':
|
|
397
397
|
case '!description':
|
|
398
398
|
case '!keywords':
|
|
399
399
|
case '!author':
|
|
400
|
-
return '(repository[\'
|
|
400
|
+
return '(repository[\'' + command.substring(1) + '\'] || \'\')';
|
|
401
401
|
|
|
402
402
|
case 'place':
|
|
403
403
|
return command.indexOf('(') === -1 ? '(repository[\'' + command + '\'] || \'\')' : 'self.' + command;
|
|
@@ -638,6 +638,13 @@ View.prototype.title = function(value) {
|
|
|
638
638
|
return '';
|
|
639
639
|
};
|
|
640
640
|
|
|
641
|
+
View.prototype.title2 = function(value) {
|
|
642
|
+
var current = this.repository.title;
|
|
643
|
+
if (value)
|
|
644
|
+
this.repository.title = (current || '') + value.safehtml();
|
|
645
|
+
return '';
|
|
646
|
+
};
|
|
647
|
+
|
|
641
648
|
View.prototype.description = function(value) {
|
|
642
649
|
this.repository.description = value;
|
|
643
650
|
return '';
|
|
@@ -676,7 +683,7 @@ View.prototype.href = function(key, value) {
|
|
|
676
683
|
|
|
677
684
|
if (type === 'string') {
|
|
678
685
|
|
|
679
|
-
var cachekey = '
|
|
686
|
+
var cachekey = 'href_' + key;
|
|
680
687
|
var str = self.repository[cachekey] || '';
|
|
681
688
|
|
|
682
689
|
if (!str) {
|
|
@@ -824,7 +831,7 @@ View.prototype.import = function() {
|
|
|
824
831
|
|
|
825
832
|
View.prototype.section = function(name, value, replace) {
|
|
826
833
|
|
|
827
|
-
var key = '
|
|
834
|
+
var key = 'section_' + name;
|
|
828
835
|
var self = this;
|
|
829
836
|
|
|
830
837
|
if (value == null)
|
|
@@ -848,6 +855,10 @@ View.prototype.url = function(hostname = false) {
|
|
|
848
855
|
return hostname ? (self.controller ? self.controller.hostname(self.controller.url) : '') : (self.controller ? self.controller.url : '');
|
|
849
856
|
};
|
|
850
857
|
|
|
858
|
+
View.prototype.set = function() {
|
|
859
|
+
return '';
|
|
860
|
+
};
|
|
861
|
+
|
|
851
862
|
View.prototype.render = function(name, model, ispartial = false) {
|
|
852
863
|
|
|
853
864
|
var self = this;
|
package/websocket.js
CHANGED
|
@@ -33,6 +33,7 @@ function Controller(req, socket, head) {
|
|
|
33
33
|
var ctrl = this;
|
|
34
34
|
|
|
35
35
|
ctrl.req = req;
|
|
36
|
+
ctrl.method = 'SOCKET';
|
|
36
37
|
ctrl.res = ctrl.socket = socket;
|
|
37
38
|
ctrl.route = null;
|
|
38
39
|
ctrl.head = head;
|
|
@@ -864,10 +865,14 @@ function authorize(ctrl) {
|
|
|
864
865
|
|
|
865
866
|
function middleware(ctrl) {
|
|
866
867
|
var run = function(index) {
|
|
867
|
-
|
|
868
|
-
if (
|
|
869
|
-
fn
|
|
870
|
-
|
|
868
|
+
let key = ctrl.route.middleware[index];
|
|
869
|
+
if (key) {
|
|
870
|
+
let fn = F.routes.middleware[key];
|
|
871
|
+
if (fn)
|
|
872
|
+
fn(ctrl, () => run(index + 1));
|
|
873
|
+
else
|
|
874
|
+
prepare(ctrl);
|
|
875
|
+
} else
|
|
871
876
|
prepare(ctrl);
|
|
872
877
|
};
|
|
873
878
|
run(0);
|
|
@@ -875,7 +880,7 @@ function middleware(ctrl) {
|
|
|
875
880
|
|
|
876
881
|
function prepare(ctrl) {
|
|
877
882
|
|
|
878
|
-
ctrl.ondata2 = () =>
|
|
883
|
+
ctrl.ondata2 = () => ctrl.ondata();
|
|
879
884
|
|
|
880
885
|
var compress = (F.config.$wscompress && ctrl.headers['sec-websocket-extensions'] || '').indexOf('permessage-deflate') !== -1;
|
|
881
886
|
var header = ctrl.route.protocols && ctrl.route.protocols.length ? (compress ? SOCKET_RESPONSE_PROTOCOL_COMPRESS : SOCKET_RESPONSE_PROTOCOL).format(ctrl.sign(ctrl), ctrl.route.protocols.join(', ')) : (compress ? SOCKET_RESPONSE_COMPRESS : SOCKET_RESPONSE).format(ctrl.sign(ctrl));
|
|
@@ -1255,7 +1260,6 @@ WebSocketClient.prototype.connectforce = function(self, url, protocol, origin) {
|
|
|
1255
1260
|
|
|
1256
1261
|
self.req.on('response', function(res) {
|
|
1257
1262
|
|
|
1258
|
-
print(res.statusCode);
|
|
1259
1263
|
self.$events.error && self.emit('error', new Error('Unexpected server response (' + res.statusCode + ')'));
|
|
1260
1264
|
|
|
1261
1265
|
if (self.options.reconnectserver) {
|