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.
Files changed (59) hide show
  1. package/api.js +18 -10
  2. package/bin/flow5 +142 -0
  3. package/bin/total5 +166 -905
  4. package/builders.js +90 -35
  5. package/changelog.txt +3 -1
  6. package/cluster.js +1 -1
  7. package/cms.js +185 -51
  8. package/controller.js +233 -70
  9. package/cron.js +1 -1
  10. package/debug.js +12 -5
  11. package/edit.js +26 -33
  12. package/filestorage.js +38 -17
  13. package/flow-flowstream.js +199 -68
  14. package/flow.js +16 -10
  15. package/flowstream.js +4 -3
  16. package/global.js +84 -1
  17. package/htmlparser.js +41 -29
  18. package/http.js +3 -1
  19. package/image.js +4 -0
  20. package/images.js +1 -1
  21. package/index.js +246 -117
  22. package/jsonschema.js +21 -17
  23. package/macros.js +222 -0
  24. package/mail.js +11 -27
  25. package/markdown.js +21 -11
  26. package/minificators.js +1 -1
  27. package/nosql-querybuilder.js +4 -0
  28. package/nosql.js +8 -0
  29. package/openclient.js +1 -1
  30. package/package.json +4 -3
  31. package/pause.html +1 -1
  32. package/release.js +1 -1
  33. package/routing.js +118 -35
  34. package/sourcemap.js +6 -3
  35. package/test.js +9 -2
  36. package/tms.js +11 -14
  37. package/uibuilder.js +59 -23
  38. package/utils.js +147 -102
  39. package/viewengine.js +19 -8
  40. package/websocket.js +10 -6
  41. package/503.html +0 -65
  42. package/CONTRIBUTING.md +0 -55
  43. package/helpers/index.js +0 -32
  44. package/templates.json +0 -74
  45. package/tests/bundles/index.js +0 -25
  46. package/tests/cron.js +0 -0
  47. package/tests/htmlparser.js +0 -0
  48. package/tests/minifactors.js +0 -17
  49. package/tests/nosql.js +0 -18
  50. package/tests/proxy/index.js +0 -21
  51. package/tests/routing/index.js +0 -27
  52. package/tests/schemas.js +0 -17
  53. package/tests/server/index.js +0 -24
  54. package/tests/staticfiles/index.js +0 -24
  55. package/tests/utils.js +0 -17
  56. package/tmsclient.js +0 -125
  57. package/todo.txt +0 -11
  58. package/tools/beta.sh +0 -6
  59. package/tools/release.sh +0 -6
package/debug.js CHANGED
@@ -43,6 +43,13 @@ module.exports.watcher = function(callback) {
43
43
  runwatching();
44
44
  };
45
45
 
46
+ function killapp(pid) {
47
+ try {
48
+ process.kill(pid, 'SIGINT');
49
+ } catch (e) {
50
+ }
51
+ }
52
+
46
53
  function runapp() {
47
54
  !options && (options = {});
48
55
  if (options.servicemode) {
@@ -250,12 +257,12 @@ function runwatching() {
250
257
  var index = fn.indexOf('/', 1);
251
258
  var dir = fn.substring(0, index + 1);
252
259
 
253
- if (dir === CONF.directory_themes) {
260
+ if (dir === F.config.directory_themes) {
254
261
  index = fn.indexOf('/', index + 1);
255
262
  dir = fn.substring(index, fn.indexOf('/', index + 1) + 1);
256
263
  }
257
264
 
258
- return CONF.directory_views === dir || CONF.directory_public === dir ? fn : '';
265
+ return dir === '/views/' || dir === '/public/' ? fn : '';
259
266
  }
260
267
 
261
268
  function makestamp() {
@@ -388,7 +395,7 @@ function runwatching() {
388
395
  try
389
396
  {
390
397
  skiprestart = true;
391
- process.kill(app.pid);
398
+ killapp(app.pid);
392
399
  if (options.inspector) {
393
400
  setTimeout(restart, 1000);
394
401
  return;
@@ -471,7 +478,7 @@ function runwatching() {
471
478
  }
472
479
 
473
480
  skiprestart = true;
474
- process.kill(app.pid);
481
+ killapp(app.pid);
475
482
  app = null;
476
483
  process.exit(0);
477
484
  }
@@ -491,7 +498,7 @@ function runwatching() {
491
498
  F.Fs.unlink(pid, noop);
492
499
  if (app !== null) {
493
500
  skiprestart = true;
494
- process.kill(app.pid);
501
+ killapp(app.pid);
495
502
  }
496
503
  process.exit(0);
497
504
  }
package/edit.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Total.js Edit
2
2
  // The MIT License
3
- // Copyright 2020-2023 (c) Peter Širka <petersirka@gmail.com>
3
+ // Copyright 2020-2024 (c) Peter Širka <petersirka@gmail.com>
4
4
 
5
5
  'use strict';
6
6
 
@@ -26,8 +26,6 @@ exports.init = function(url) {
26
26
  return;
27
27
  }
28
28
 
29
- console.log(msg);
30
-
31
29
  F.action('editor', msg).callback(function(err, response) {
32
30
 
33
31
  if (err) {
@@ -165,17 +163,7 @@ F.newaction('editor', {
165
163
  });
166
164
 
167
165
  function mkdir(path, callback) {
168
- var a = '/';
169
- path = path.split('/').trim();
170
- path.wait(function(p, next) {
171
- a = a + p + '/';
172
- F.Fs.lstat(a, function(err) {
173
- if (err)
174
- F.Fs.mkdir(a, next);
175
- else
176
- next();
177
- });
178
- }, callback);
166
+ F.Fs.mkdir(path, { recursive: true }, callback);
179
167
  }
180
168
 
181
169
  function browse($, model) {
@@ -204,11 +192,11 @@ function browse($, model) {
204
192
 
205
193
  $.callback({ files: files, directories: directories });
206
194
 
207
- }, validator);
195
+ }, validator, true);
208
196
  }
209
197
 
210
198
  function log($, model) {
211
- var filename = F.path.root(model.path);
199
+ var filename = F.Path.normalize(F.path.root(model.path));
212
200
  F.Fs.stat(filename, function(err, stats) {
213
201
  if (stats) {
214
202
  var start = stats.size - (1024 * 4); // Max. 4 kB
@@ -231,7 +219,7 @@ function clearlog($, model) {
231
219
  }
232
220
 
233
221
  function load($, model) {
234
- var filename = F.path.root(model.path);
222
+ var filename = F.Path.normalize(F.path.root(model.path));
235
223
  F.Fs.readFile(filename, function(err, data) {
236
224
 
237
225
  if (err) {
@@ -264,20 +252,20 @@ function save($, model) {
264
252
  // Tries to create a folder
265
253
  var filename = F.path.root(model.path);
266
254
  var name = F.TUtils.getName(model.path);
267
- var directory = filename.substring(0, filename.length - name.length);
255
+ var directory = F.Path.normalize(filename.substring(0, filename.length - name.length));
268
256
 
269
- F.Fs.mkdir(directory, { recursive: true }, function() {
257
+ mkdir(directory, function() {
270
258
  decodedata(model, function(err, buffer) {
271
259
  if (err)
272
260
  $.invalid(err);
273
261
  else
274
- F.Fs.writeFile(filename, buffer, $.done());
262
+ F.Fs.writeFile(F.Path.normalize(filename), buffer, $.done());
275
263
  });
276
264
  });
277
265
  }
278
266
 
279
267
  function remove($, model) {
280
- var filename = F.path.root(model.path);
268
+ var filename = F.Path.normalize(F.path.root(model.path));
281
269
  try {
282
270
  var stats = F.Fs.lstatSync(filename);
283
271
  if (stats.isFile()) {
@@ -294,12 +282,12 @@ function remove($, model) {
294
282
  }
295
283
 
296
284
  function info($, model) {
297
- var filename = F.path.root(model.path);
285
+ var filename = F.Path.normalize(F.path.root(model.path));
298
286
  F.Fs.lstat(filename, $.callback);
299
287
  }
300
288
 
301
289
  function download($, model) {
302
- var filename = F.path.root(model.path);
290
+ var filename = F.Path.normalize(F.path.root(model.path));
303
291
  var ext = F.TUtils.getExtension(model.path);
304
292
  F.Fs.lstat(filename, function(err, stats) {
305
293
  if (err || stats.isDirectory() || stats.isSocket()) {
@@ -328,7 +316,7 @@ function download($, model) {
328
316
  }
329
317
 
330
318
  function send($, model) {
331
- var filename = F.path.root(model.path);
319
+ var filename = F.Path.normalize(F.path.root(model.path));
332
320
  F.Fs.fstat(filename, function() {
333
321
  var opt = {};
334
322
  opt.method = 'GET';
@@ -340,7 +328,7 @@ function send($, model) {
340
328
  }
341
329
 
342
330
  function customimport($, model) {
343
- var filename = F.path.root(model.path);
331
+ var filename = F.Path.normalize(F.path.root(model.path));
344
332
  DOWNLOAD(model.data, filename, $.done());
345
333
  }
346
334
 
@@ -356,8 +344,8 @@ function rename($, model) {
356
344
 
357
345
  data = data.response;
358
346
 
359
- data.newpath = F.path.root(data.newpath);
360
- data.oldpath = F.path.root(data.oldpath);
347
+ data.newpath = F.Path.normalize(F.path.root(data.newpath));
348
+ data.oldpath = F.Path.normalize(F.path.root(data.oldpath));
361
349
 
362
350
  mkdir(F.Path.dirname(data.newpath), function() {
363
351
  F.Fs.rename(data.oldpath, data.newpath, $.done());
@@ -366,7 +354,12 @@ function rename($, model) {
366
354
 
367
355
  function create($, model) {
368
356
 
369
- var filename = F.path.root(model.path);
357
+ // model.path {String}
358
+ // model.data {Object}
359
+ // model.data.clone {String}
360
+ // model.data.folder {Boolean}
361
+
362
+ var filename = F.Path.normalize(F.path.root(model.path));
370
363
  var data = (model.data || '{}').parseJSON();
371
364
 
372
365
  F.Fs.lstat(filename, function(err) {
@@ -376,14 +369,14 @@ function create($, model) {
376
369
  // we can continue
377
370
  if (data.folder) {
378
371
  if (model.clone)
379
- F.Fs.cp(F.path.root(data.clone), filename, { recursive: true, force: true }, $.done());
372
+ F.Fs.cp(F.Path.normalize(F.path.root(data.clone)), filename, { recursive: true, force: true }, $.done());
380
373
  else
381
374
  mkdir(filename, $.done());
382
375
  } else {
383
376
  var name = F.TUtils.getName(filename);
384
377
  mkdir(filename.substring(0, filename.length - name.length), function() {
385
378
  if (data.clone)
386
- F.Fs.copyFile(F.path.root(data.clone), filename, $.done());
379
+ F.Fs.copyFile(F.Path.normalize(F.path.root(data.clone)), filename, $.done());
387
380
  else
388
381
  F.Fs.writeFile(filename, '', $.done());
389
382
  });
@@ -395,8 +388,8 @@ function create($, model) {
395
388
 
396
389
  function upload($, model) {
397
390
  var name = F.TUtils.getName(model.path);
398
- var filename = F.path.root(model.path);
399
- var directory = F.path.root(model.path.substring(0, model.length - name.length));
391
+ var filename = F.Path.normalize(F.path.root(model.path));
392
+ var directory = F.Path.normalize(F.path.root(model.path.substring(0, model.length - name.length)));
400
393
  mkdir(directory, function() {
401
394
  decodedata(model, function(err, buffer) {
402
395
  if (err)
@@ -416,7 +409,7 @@ function modify($, model) {
416
409
 
417
410
  function wiki($) {
418
411
 
419
- var path = F.path.root();
412
+ var path = F.Path.normalize(PATH.root());
420
413
 
421
414
  F.TUtils.ls(path, function(files) {
422
415
 
package/filestorage.js CHANGED
@@ -7,6 +7,7 @@
7
7
  const IMAGES = { jpg: 1, png: 1, gif: 1, svg: 1, jpeg: 1, heic: 1, heif: 1, webp: 1, tiff: 1, bmp: 1 };
8
8
  const HEADERSIZE = 2000;
9
9
  const MKDIR = { recursive: true };
10
+ const READDIR = { withFileTypes: true };
10
11
  const GZIP_FILE = { memLevel: 9 };
11
12
 
12
13
  const REG_RANGE = /bytes=/;
@@ -435,7 +436,7 @@ FP._readbuffer = function(id, callback) {
435
436
  FP.browse = function(callback) {
436
437
  var db = NOSQL(this.logger).find();
437
438
  if (callback)
438
- db.$callback = callback;
439
+ db.main.callback = callback;
439
440
  return db;
440
441
  };
441
442
 
@@ -743,11 +744,11 @@ FP._clear = function(callback) {
743
744
  return self;
744
745
  };
745
746
 
746
- FP.stream = function(onfile, callback, workers) {
747
+ FP.stream = function(onfile, callback, workers = 2) {
747
748
 
748
749
  var self = this;
749
750
 
750
- F.Fs.readdir(self.directory, function(err, response) {
751
+ F.Fs.readdir(self.directory, READDIR, function(err, response) {
751
752
 
752
753
  if (err) {
753
754
  callback();
@@ -758,15 +759,33 @@ FP.stream = function(onfile, callback, workers) {
758
759
 
759
760
  response.wait(function(item, next) {
760
761
 
761
- if (item.length !== 4) {
762
+ if (!item.isDirectory()) {
763
+ next();
764
+ return;
765
+ }
766
+
767
+ if (item.name.length !== 4) {
762
768
  next();
763
769
  return;
764
770
  }
765
771
 
766
- F.Fs.readdir(F.Path.join(self.directory, item), function(err, files) {
772
+ F.Fs.readdir(F.Path.join(self.directory, item.name), READDIR, function(err, files) {
767
773
  if (files instanceof Array) {
768
774
  files.wait(function(item, next) {
769
- var id = item.substring(0, item.lastIndexOf('.'));
775
+
776
+ if (!item.isFile()) {
777
+ next();
778
+ return;
779
+ }
780
+
781
+ let index = item.name.lastIndexOf('.');
782
+
783
+ if (item.name.substring(index) !== '.file') {
784
+ next();
785
+ return;
786
+ }
787
+
788
+ let id = item.name.substring(0, index);
770
789
  self.read(id, function(err, meta) {
771
790
  if (meta) {
772
791
  meta.id = id;
@@ -954,7 +973,7 @@ FP.http = function(ctrl, opt) {
954
973
 
955
974
  var self = this;
956
975
 
957
- if (F.temporary.notfound[ctrl.uri.key]) {
976
+ if (F.temporary.notfound[ctrl.uri.cache]) {
958
977
  ctrl.fallback(404);
959
978
  return;
960
979
  }
@@ -966,7 +985,7 @@ FP.http = function(ctrl, opt) {
966
985
  fd && F.Fs.close(fd, NOOP);
967
986
 
968
987
  if (err || (obj.expire && obj.expire < NOW) || (opt.check && opt.check(obj) == false)) {
969
- F.temporary.notfound[ctrl.uri.key] = true;
988
+ F.temporary.notfound[ctrl.uri.cache] = true;
970
989
  ctrl.fallback(404);
971
990
  return;
972
991
  }
@@ -976,17 +995,11 @@ FP.http = function(ctrl, opt) {
976
995
  var date = obj.date ? obj.date.toUTCString() : '';
977
996
  var response = ctrl.response;
978
997
 
979
- if (!opt.download && ctrl.headers['if-modified-since'] === date) {
980
- response.status = 304;
981
- response.headers['cache-control'] = 'public, max-age=11111111';
982
- response.headers['last-modified'] = date;
983
- ctrl.flush();
984
- F.stats.response.notmodified++;
998
+ if (!opt.download && date && ctrl.notmodified(date))
985
999
  return;
986
- }
987
1000
 
988
1001
  // Resized image?
989
- if (!DEBUG && F.temporary.path[ctrl.uri.key]) {
1002
+ if (!DEBUG && F.temporary.path[ctrl.uri.cache]) {
990
1003
  ctrl.resume();
991
1004
  return;
992
1005
  }
@@ -1047,7 +1060,10 @@ FP.http = function(ctrl, opt) {
1047
1060
 
1048
1061
  response.status = 206;
1049
1062
  response.headers['accept-ranges'] = 'bytes';
1050
- response.headers['cache-control'] = DEBUG ? 'private, no-cache, no-store, max-age=0' : 'public, max-age=11111111';
1063
+
1064
+ if (!opt.download && !DEBUG && date)
1065
+ ctrl.httpcache(date);
1066
+
1051
1067
  response.headers['content-length'] = length;
1052
1068
  response.headers['content-range'] = 'bytes ' + beg + '-' + end + '/' + obj.size;
1053
1069
  response.headers['content-type'] = obj.type;
@@ -1057,9 +1073,14 @@ FP.http = function(ctrl, opt) {
1057
1073
 
1058
1074
  ctrl.res.writeHead(response.status, response.headers);
1059
1075
  F.Fs.createReadStream(filename, { flags: 'r', mode: '0666', autoClose: true, start: HEADERSIZE + beg, end: end + HEADERSIZE }).pipe(ctrl.res);
1076
+ ctrl.free();
1060
1077
 
1061
1078
  } else {
1062
1079
  var stream = F.Fs.createReadStream(filename, { start: HEADERSIZE });
1080
+
1081
+ if (!opt.download && !DEBUG && date)
1082
+ ctrl.httpcache(date);
1083
+
1063
1084
  ctrl.stream(obj.type, stream);
1064
1085
  }
1065
1086
  }