total5 0.0.1 → 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/LICENSE ADDED
@@ -0,0 +1,211 @@
1
+ The MIT License
2
+ Copyright 2012-2024 (c) Peter Širka <petersirka@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ persons to whom the Software is furnished to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ === Encrypt & Decrypt (index.js)
24
+
25
+ The MIT License (MIT)
26
+ Copyright (c) 2011 Jozef Gula <gula.jozef@gmail.com>
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a
29
+ copy of this software and associated documentation files (the
30
+ "Software"), to deal in the Software without restriction, including
31
+ without limitation the rights to use, copy, modify, merge, publish,
32
+ distribute, sublicense, and/or sell copies of the Software, and to permit
33
+ persons to whom the Software is furnished to do so, subject to the
34
+ following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included
37
+ in all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
40
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
42
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
43
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
44
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
45
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
46
+
47
+ === WebSocket encode/decode (index.js, utils.js)
48
+
49
+ The MIT License (MIT)
50
+ Copyright (c) 2014 Jozef Gula <gula.jozef@gmail.com>
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a
53
+ copy of this software and associated documentation files (the
54
+ "Software"), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to permit
57
+ persons to whom the Software is furnished to do so, subject to the
58
+ following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be included
61
+ in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
64
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
66
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
67
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
68
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
69
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
70
+
71
+ === Get PNG/JPG image size (internal.js)
72
+
73
+ The MIT License (MIT)
74
+ Copyright (c) 2012 TJ Holowaychuk, visionmedia (http://tjholowaychuk.com)
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining a
77
+ copy of this software and associated documentation files (the
78
+ "Software"), to deal in the Software without restriction, including
79
+ without limitation the rights to use, copy, modify, merge, publish,
80
+ distribute, sublicense, and/or sell copies of the Software, and to permit
81
+ persons to whom the Software is furnished to do so, subject to the
82
+ following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be included
85
+ in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
88
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
90
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
91
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
92
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
93
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
94
+
95
+ === EE First (internal.js)
96
+
97
+ The MIT License (MIT)
98
+ Copyright (c) 2014 Jonathan Ong me@jongleberry.com
99
+
100
+ Permission is hereby granted, free of charge, to any person obtaining a copy
101
+ of this software and associated documentation files (the "Software"), to deal
102
+ in the Software without restriction, including without limitation the rights
103
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
104
+ copies of the Software, and to permit persons to whom the Software is
105
+ furnished to do so, subject to the following conditions:
106
+
107
+ The above copyright notice and this permission notice shall be included in
108
+ all copies or substantial portions of the Software.
109
+
110
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
111
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
112
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
113
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
114
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
115
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
116
+ THE SOFTWARE.
117
+
118
+ === on-finished (internal.js)
119
+
120
+ The MIT License (MIT)
121
+ Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
122
+ Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
123
+
124
+ Permission is hereby granted, free of charge, to any person obtaining
125
+ a copy of this software and associated documentation files (the
126
+ 'Software'), to deal in the Software without restriction, including
127
+ without limitation the rights to use, copy, modify, merge, publish,
128
+ distribute, sublicense, and/or sell copies of the Software, and to
129
+ permit persons to whom the Software is furnished to do so, subject to
130
+ the following conditions:
131
+
132
+ The above copyright notice and this permission notice shall be
133
+ included in all copies or substantial portions of the Software.
134
+
135
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
136
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
137
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
138
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
139
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
140
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
141
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
142
+
143
+ === Shellsort algorithm (utils.js)
144
+
145
+ Source: https://www.khanacademy.org/computer-programming/sort-algorithms/6199294078746624
146
+
147
+ The MIT License (MIT)
148
+ Copyright (c) 2014 Sean McCarren
149
+
150
+ Permission is hereby granted, free of charge, to any person obtaining
151
+ a copy of this software and associated documentation files (the
152
+ 'Software'), to deal in the Software without restriction, including
153
+ without limitation the rights to use, copy, modify, merge, publish,
154
+ distribute, sublicense, and/or sell copies of the Software, and to
155
+ permit persons to whom the Software is furnished to do so, subject to
156
+ the following conditions:
157
+
158
+ The above copyright notice and this permission notice shall be
159
+ included in all copies or substantial portions of the Software.
160
+
161
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
162
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
163
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
165
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
166
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
167
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
168
+
169
+ === LDAP utilities (ldap.js)
170
+
171
+ Copyright (c) 2011 Mark Cavage, All rights reserved.
172
+
173
+ Permission is hereby granted, free of charge, to any person obtaining a copy
174
+ of this software and associated documentation files (the "Software"), to deal
175
+ in the Software without restriction, including without limitation the rights
176
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
177
+ copies of the Software, and to permit persons to whom the Software is
178
+ furnished to do so, subject to the following conditions:
179
+
180
+ The above copyright notice and this permission notice shall be included in
181
+ all copies or substantial portions of the Software.
182
+
183
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
189
+ THE SOFTWARE
190
+
191
+ ---
192
+
193
+ Copyright (c) 2019 LDAPjs, All rights reserved.
194
+
195
+ Permission is hereby granted, free of charge, to any person obtaining a copy
196
+ of this software and associated documentation files (the "Software"), to deal
197
+ in the Software without restriction, including without limitation the rights
198
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
199
+ copies of the Software, and to permit persons to whom the Software is
200
+ furnished to do so, subject to the following conditions:
201
+
202
+ The above copyright notice and this permission notice shall be included in
203
+ all copies or substantial portions of the Software.
204
+
205
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
206
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
208
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
209
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
210
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
211
+ THE SOFTWARE
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Total.js framework 5
2
+ ====================
3
+
4
+ [![Made in EU](https://cdn.componentator.com/eu-small.png)](https://european-union.europa.eu/)
5
+
6
+ - [Website](https://www.totaljs.com/)
7
+ - [__Documentation__](https://docs.totaljs.com/total5/)
8
+ - [Chat support](https://platform.totaljs.com/?open=messenger)
9
+ - [Join __Total.js Telegram__](https://t.me/totalplatform)
10
+ - [Support](https://www.totaljs.com/support/)
11
+
12
+ __Total.js framework v5__ is the framework for Node.js platform written in `pure` JavaScript similar to PHP's Laravel or Python's Django or ASP.NET MVC. It can be used as a web, desktop, service, or IoT application.
13
+
14
+ ```bash
15
+ $ npm install total5
16
+ ```
17
+
18
+ ## Social networks
19
+
20
+ Please support the framework on social networks.
21
+
22
+ - [Follow Total.js on Gitter](https://gitter.im/totaljs/framework)
23
+ - [Follow Total.js on GitHub](https://github.com/totaljs)
24
+ - [Follow Total.js on Twitter - __@totalframework__](https://twitter.com/totalframework)
25
+ - [Follow Total.js on Facebook](https://www.facebook.com/totaljs.web.framework)
26
+ - [Follow Total.js on LinkedIn](https://www.linkedin.com/company/total-avengers/)
27
+
28
+ ## Contact
29
+
30
+ - Contact <https://www.totaljs.com/contact/>
31
+ - [Chat support](https://platform.totaljs.com/?open=messenger)
32
+ - [Join to __Total.js Telegram__](https://t.me/totalplatform)
package/api.js ADDED
@@ -0,0 +1,297 @@
1
+ // API caller
2
+ // The MIT License
3
+ // Copyright 2023 (c) Peter Širka <petersirka@gmail.com>
4
+
5
+ 'use strict';
6
+
7
+ const REG_BINARY = /image|document|sheet|excel|msword|video|audio|zip|pdf/;
8
+ const REG_TEXT = /^text\/(html|plain|xml)/;
9
+
10
+ var cache = {};
11
+
12
+ // Registers a new API type
13
+ exports.newapi = function(type, callback) {
14
+
15
+ if (typeof(type) === 'function') {
16
+ callback = type;
17
+ type = 'default';
18
+ }
19
+
20
+ if (type.indexOf(',') !== -1) {
21
+ var arr = type.split(',').trim();
22
+ for (var m of arr)
23
+ exports.newapi(m, callback);
24
+ return;
25
+ }
26
+
27
+ // It can be "camel case"
28
+ var lower = type.toLowerCase();
29
+ cache[type] = lower;
30
+ cache[lower] = lower;
31
+
32
+ if (callback)
33
+ F.apiservices[lower] = callback;
34
+ else
35
+ delete F.apiservices[lower];
36
+
37
+ };
38
+
39
+ function APICall() {
40
+ var t = this;
41
+ t.options = {};
42
+ }
43
+
44
+ const APICallProto = APICall.prototype;
45
+
46
+ APICallProto.output = function(type) {
47
+ this.options.output = type;
48
+ return this;
49
+ };
50
+
51
+ APICallProto.promise = function($) {
52
+ var t = this;
53
+ var promise = new Promise(function(resolve, reject) {
54
+ t.$callback = function(err, response) {
55
+ if (err) {
56
+ if ($ && $.invalid) {
57
+ $.invalid(err);
58
+ } else
59
+ reject(F.TUtils.toError(err));
60
+ } else
61
+ resolve(response);
62
+ };
63
+ });
64
+
65
+ return promise;
66
+ };
67
+
68
+ APICallProto.audit = function($, message, type) {
69
+ var t = this;
70
+ t.$audit = function() {
71
+ // Dynamic arguments
72
+ if (message)
73
+ message = $.variables(message, t.options.data);
74
+ $.audit(message, type);
75
+ };
76
+ return t;
77
+ };
78
+
79
+ APICallProto.done = function($, callback) {
80
+ var t = this;
81
+ t.$callback = function(err, response) {
82
+ if (err)
83
+ $.invalid(err);
84
+ else if (callback)
85
+ callback(response);
86
+ t.free();
87
+ };
88
+ return t;
89
+ };
90
+
91
+ APICallProto.debug = function() {
92
+ this.$debug = true;
93
+ return this;
94
+ };
95
+
96
+ APICallProto.fail = function(cb) {
97
+ this.$callback_fail = cb;
98
+ return this;
99
+ };
100
+
101
+ APICallProto.data = function(cb) {
102
+ this.$callback_data = cb;
103
+ return this;
104
+ };
105
+
106
+ APICallProto.controller = function($) {
107
+ this.options.controller = $.controller || $;
108
+ return this;
109
+ };
110
+
111
+ APICallProto.file = function(filename, path, name) {
112
+
113
+ var t = this;
114
+
115
+ if (!t.options.files)
116
+ t.options.files = [];
117
+
118
+ var obj = { name: name || ('file' + t.options.files.length), filename: filename, path: path };
119
+
120
+ if (t.options.files)
121
+ t.options.files.push(obj);
122
+ else
123
+ t.options.files = [obj];
124
+
125
+ return t;
126
+ };
127
+
128
+ APICallProto.error = APICallProto.err = function(err, reverse) {
129
+ this.$error = err + '';
130
+ this.$error_reverse = reverse;
131
+ return this;
132
+ };
133
+
134
+ APICallProto.callback = function($) {
135
+ var t = this;
136
+ t.$callback = typeof($) === 'function' ? $ : $.callback();
137
+ return t;
138
+ };
139
+
140
+ APICallProto.evaluate = function(err, response) {
141
+
142
+ var t = this;
143
+ if (!err && t.$error) {
144
+ if (t.$error_reverse) {
145
+ if (response)
146
+ err = t.$error;
147
+ else if (response instanceof Array && response.length)
148
+ err = t.$error;
149
+ } else if (!response)
150
+ err = t.$error;
151
+ else if (response instanceof Array && !response.length)
152
+ err = t.$error;
153
+ }
154
+
155
+ if (err) {
156
+ t.$callback_fail && t.$callback_fail(err);
157
+ } else {
158
+ if (t.$audit) {
159
+ t.$audit();
160
+ t.$audit = null;
161
+ }
162
+ t.$callback_data && t.$callback_data(response);
163
+ }
164
+
165
+ t.$debug && console.log('--DEBUG-- API: ' + t.options.name + ' --> ' + t.options.schema, '|', 'Error:', err, '|', 'Response:', response);
166
+ t.$callback && t.$callback(err, response);
167
+ };
168
+
169
+ function execapi(api) {
170
+ var conn = F.apiservices[cache[api.options.name]] || F.apiservices['*'];
171
+ if (conn)
172
+ conn.call(api, api.options, (err, response) => api.evaluate(err, response));
173
+ else
174
+ api.evaluate('API is not initialized');
175
+ }
176
+
177
+ // Executes API
178
+ exports.exec = function(name, schema, data, $) {
179
+ var api = new APICall();
180
+ api.options.name = cache[name] || name;
181
+ api.options.schema = schema;
182
+ api.options.data = data;
183
+ api.options.controller = $;
184
+ setImmediate(execapi, api);
185
+ return api;
186
+ };
187
+
188
+ exports.newapi('TotalAPI,TAPI', function(opt, next) {
189
+
190
+ if (!F.config.$tapi && opt.schema !== 'check') {
191
+ next('totalapi_inactive');
192
+ return;
193
+ }
194
+
195
+ if (opt.data && typeof(opt.data) !== 'object')
196
+ opt.data = { value: opt.data };
197
+
198
+ var req = {};
199
+
200
+ req.method = 'POST';
201
+ req.url = 'https://' + F.config.$tapiurl + '.api.totaljs.com/' + opt.schema + '/';
202
+
203
+ if (opt.files) {
204
+ req.body = opt.data;
205
+ req.files = opt.files;
206
+ } else
207
+ req.body = JSON.stringify(opt.data);
208
+
209
+ req.type = 'json';
210
+ req.timeout = 60000;
211
+ req.keepalive = true;
212
+ req.headers = { 'x-token': opt.token || F.config.totalapi || F.config.secret_totalapi || F.config.$tapisecret || '-', 'x-app': encodeURIComponent(F.config.name) };
213
+ req.custom = true;
214
+
215
+ req.callback = function(err, response) {
216
+
217
+ if (err) {
218
+ next(err.toString());
219
+ return;
220
+ }
221
+
222
+ var buffer = [];
223
+
224
+ // Error
225
+ if (response.status > 200) {
226
+ response.stream.on('data', chunk => buffer.push(chunk));
227
+ F.cleanup(response.stream, function() {
228
+ let output = Buffer.concat(buffer).toString('utf8');
229
+ let response = output.parseJSON();
230
+ next((response && response[0] && response[0].error) || output);
231
+ });
232
+ return;
233
+ }
234
+
235
+ if (!opt.output || opt.output === 'json' || opt.output === 'html' || opt.output === 'plain' || opt.output === 'text' || opt.output === 'base64' || opt.output === 'buffer' || opt.output === 'binary') {
236
+ response.stream.on('data', chunk => buffer.push(chunk));
237
+ F.cleanup(response.stream, function() {
238
+ let output = Buffer.concat(buffer);
239
+ if (opt.output === 'base64') {
240
+ output = output.toString('base64');
241
+ } else if (opt.output !== 'binary' && opt.output !== 'buffer') {
242
+ var type = response.headers['content-type'];
243
+
244
+ if (REG_BINARY.test(type)) {
245
+ next(null, output);
246
+ return;
247
+ }
248
+
249
+ output = output.toString('utf8');
250
+
251
+ if (REG_TEXT.test(type)) {
252
+ next(null, output);
253
+ } else if (!opt.output || opt.output === 'json')
254
+ output = output.parseJSON(true);
255
+ }
256
+ next(null, output);
257
+ });
258
+ return;
259
+ }
260
+
261
+ if (opt.output === 'stream') {
262
+ next(null, response.stream);
263
+ return;
264
+ }
265
+
266
+ // FileStorage in the form: "#name id filename"
267
+ if (opt.output[0] === '#') {
268
+
269
+ var fsdata = null;
270
+ var fs = null;
271
+
272
+ if (opt.output[0] === '#') {
273
+ fsdata = opt.output.substring(1).split(' ');
274
+ fs = F.filestorage(fsdata[0]);
275
+ }
276
+
277
+ var type = (response.headers['content-type'] || '').toLowerCase();
278
+ var index = type.lastIndexOf(';');
279
+ if (index !== -1)
280
+ type = type.substring(0, index);
281
+
282
+ var ext = type ? F.TUtils.getExtensionFromContentType(type) : 'bin';
283
+ var id = fsdata[1] || UID();
284
+ var filename = fsdata[2] || id + '.' + ext;
285
+
286
+ response.stream.pause();
287
+ fs.save(id, filename, response.stream, next);
288
+ return;
289
+ }
290
+
291
+ var writer = F.Fs.createWriteStream(opt.output);
292
+ response.stream.pipe(writer);
293
+ F.cleanup(writer, () => opt.next(null, opt.output));
294
+ };
295
+
296
+ F.TUtils.request(req);
297
+ });
package/bin/flow5 ADDED
@@ -0,0 +1,142 @@
1
+ #! /usr/bin/env node
2
+
3
+ require('total5');
4
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1;
5
+
6
+ const ARGS = process.argv; // TEST: ['-', '-', 'CMD']
7
+ const DIR = process.cwd();
8
+ const Paths = {};
9
+ const KeyToPath = {};
10
+
11
+ function load(args) {
12
+
13
+ var paths = [];
14
+ var port = 8000;
15
+
16
+ for (let i = 2; i < args.length; i++) {
17
+ var arg = args[i];
18
+ if ((/^\d+$/).test(arg))
19
+ port = +arg;
20
+ else
21
+ paths.push(arg.trim().replace(/"/g, ''));
22
+ }
23
+
24
+ console.log('[Total.js v5 Flow Engine]');
25
+
26
+ if (paths.length)
27
+ FUNC.server(paths, port);
28
+ else
29
+ FUNC.help();
30
+ }
31
+
32
+ setTimeout(load, 10, ARGS);
33
+
34
+ FUNC.help = function() {
35
+ console.log('flow5 [path or URL address] [PORT_NUMBER]');
36
+ console.log('flow5 path/to/flowschema.json');
37
+ console.log('flow5 flow1.json flow2.json flowN.json 8001');
38
+ console.log('flow5 https://yourdomain.com/flowschema.json');
39
+ };
40
+
41
+ FUNC.server = function(paths, port) {
42
+
43
+ F.config.$imprint = false;
44
+ F.config.$dirpublic = DIR;
45
+ F.config.$sourcemap = false;
46
+ F.config.$minifyjs = false;
47
+ F.config.$minifycss = false;
48
+ F.config.$minifyhtml = false;
49
+
50
+ var notify = $ => Flow.notify($, $.params.id);
51
+ var count = 0;
52
+
53
+ ROUTE('GET /notify/{id}/', notify);
54
+ ROUTE('POST /notify/{id}/ <1MB', notify);
55
+
56
+ ROUTE('SOCKET /flowstreams/{id}/ <8MB', function($) {
57
+ $.autodestroy();
58
+ Flow.socket($.params.id, $);
59
+ });
60
+
61
+ Flow.on('save', function(schema) {
62
+
63
+ // var cache = Paths[schema.id];
64
+ var path = KeyToPath[schema.id];
65
+ var cache = Paths[path];
66
+
67
+ // Check HTTPS/HTTP source
68
+ if (!cache)
69
+ return;
70
+
71
+ if (cache.components && cache.design) {
72
+ // single file
73
+ Total.Fs.writeFile(path, JSON.stringify(schema, null, '\t'), NOOP);
74
+ } else {
75
+ // Multi-flow
76
+ if (cache[schema.id]) {
77
+ cache[schema.id] = schema;
78
+ Total.Fs.writeFile(path, JSON.stringify(cache, null, '\t'), NOOP);
79
+ }
80
+ }
81
+
82
+ });
83
+
84
+ console.error('|--- http://127.0.0.1:' + port);
85
+
86
+ paths.wait(async function(path, next) {
87
+
88
+ var meta = null;
89
+
90
+ if ((/^http(s):\/\//).test(path)) {
91
+ meta = await RESTBuilder.GET(path).promise();
92
+ } else {
93
+ meta = await F.readfile(path, 'utf8');
94
+ meta = meta.parseJSON(true);
95
+ Paths[path] = meta;
96
+ }
97
+
98
+ if (!meta) {
99
+ console.error('ERROR:', 'invalid meta -', path);
100
+ next();
101
+ return;
102
+ }
103
+
104
+ if (meta.components && meta.design) {
105
+ var tmp = {};
106
+ tmp[meta.id] = meta;
107
+ meta = tmp;
108
+ }
109
+
110
+ Object.keys(meta).wait(function(key, resume, index) {
111
+
112
+ if (key === 'variables') {
113
+ resume();
114
+ return;
115
+ }
116
+
117
+ KeyToPath[key] = path;
118
+
119
+ var flowstream = meta[key];
120
+
121
+ if (!flowstream.id)
122
+ flowstream.id = path.makeid() + (index ? index : '');
123
+
124
+ Flow.load(flowstream, function(err) {
125
+
126
+ if (err)
127
+ console.error('ERROR:', err);
128
+ else {
129
+ console.log('|--- {0}:'.format(flowstream.name || flowstream.id), 'https://flow.totaljs.com/?socket=' + encodeURIComponent('http://127.0.0.1:{0}/flowstreams/{1}/'.format(port, flowstream.id)));
130
+ count++;
131
+ }
132
+
133
+ resume();
134
+ });
135
+
136
+ }, next);
137
+
138
+ }, function() {
139
+ count && F.http({ load: 'none', port: port });
140
+ });
141
+
142
+ };