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/api.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
+
const REG_BINARY = /image|document|sheet|excel|msword|video|audio|zip|pdf/;
|
|
8
|
+
const REG_TEXT = /^text\/(html|plain|xml)/;
|
|
9
|
+
|
|
7
10
|
var cache = {};
|
|
8
11
|
|
|
9
12
|
// Registers a new API type
|
|
@@ -52,10 +55,8 @@ APICallProto.promise = function($) {
|
|
|
52
55
|
if (err) {
|
|
53
56
|
if ($ && $.invalid) {
|
|
54
57
|
$.invalid(err);
|
|
55
|
-
} else
|
|
56
|
-
|
|
57
|
-
reject(err);
|
|
58
|
-
}
|
|
58
|
+
} else
|
|
59
|
+
reject(F.TUtils.toError(err));
|
|
59
60
|
} else
|
|
60
61
|
resolve(response);
|
|
61
62
|
};
|
|
@@ -208,7 +209,7 @@ exports.newapi('TotalAPI,TAPI', function(opt, next) {
|
|
|
208
209
|
req.type = 'json';
|
|
209
210
|
req.timeout = 60000;
|
|
210
211
|
req.keepalive = true;
|
|
211
|
-
req.headers = { 'x-token': opt.token || F.config.secret_totalapi || F.config.$tapisecret || '-', 'x-app': encodeURIComponent(F.config.name) };
|
|
212
|
+
req.headers = { 'x-token': opt.token || F.config.totalapi || F.config.secret_totalapi || F.config.$tapisecret || '-', 'x-app': encodeURIComponent(F.config.name) };
|
|
212
213
|
req.custom = true;
|
|
213
214
|
|
|
214
215
|
req.callback = function(err, response) {
|
|
@@ -238,8 +239,18 @@ exports.newapi('TotalAPI,TAPI', function(opt, next) {
|
|
|
238
239
|
if (opt.output === 'base64') {
|
|
239
240
|
output = output.toString('base64');
|
|
240
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
|
+
|
|
241
249
|
output = output.toString('utf8');
|
|
242
|
-
|
|
250
|
+
|
|
251
|
+
if (REG_TEXT.test(type)) {
|
|
252
|
+
next(null, output);
|
|
253
|
+
} else if (!opt.output || opt.output === 'json')
|
|
243
254
|
output = output.parseJSON(true);
|
|
244
255
|
}
|
|
245
256
|
next(null, output);
|
|
@@ -279,10 +290,7 @@ exports.newapi('TotalAPI,TAPI', function(opt, next) {
|
|
|
279
290
|
|
|
280
291
|
var writer = F.Fs.createWriteStream(opt.output);
|
|
281
292
|
response.stream.pipe(writer);
|
|
282
|
-
F.cleanup(writer,
|
|
283
|
-
opt.next(null, opt.output);
|
|
284
|
-
});
|
|
285
|
-
|
|
293
|
+
F.cleanup(writer, () => opt.next(null, opt.output));
|
|
286
294
|
};
|
|
287
295
|
|
|
288
296
|
F.TUtils.request(req);
|
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
|
+
};
|