isite 2023.12.18 → 2023.12.19
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/lib/fsm.js +13 -6
- package/lib/routing.js +70 -47
- package/object-options/index.js +1 -0
- package/package.json +1 -1
package/lib/fsm.js
CHANGED
|
@@ -171,16 +171,22 @@ module.exports = function init(____0) {
|
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
fsm.off = function (path) {
|
|
174
|
+
if (path && Array.isArray(path)) {
|
|
175
|
+
path.forEach((p) => {
|
|
176
|
+
fsm.off(p);
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (typeof path === 'object') {
|
|
181
|
+
path = path.path;
|
|
182
|
+
}
|
|
183
|
+
path = fsm.getFilePath(path);
|
|
174
184
|
if (path && typeof path == 'string') {
|
|
175
185
|
for (let i = fsm.list.length; i--; ) {
|
|
176
186
|
if (fsm.list[i] && fsm.list[i].path.like(path)) {
|
|
177
187
|
fsm.list.splice(i, 1);
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
|
-
} else if (path && Array.isArray(path)) {
|
|
181
|
-
path.forEach((p) => {
|
|
182
|
-
fsm.off(p);
|
|
183
|
-
});
|
|
184
190
|
}
|
|
185
191
|
};
|
|
186
192
|
|
|
@@ -245,7 +251,7 @@ module.exports = function init(____0) {
|
|
|
245
251
|
}
|
|
246
252
|
});
|
|
247
253
|
};
|
|
248
|
-
|
|
254
|
+
|
|
249
255
|
fsm.readFile = function (path, callback) {
|
|
250
256
|
path = fsm.getFilePath(path);
|
|
251
257
|
|
|
@@ -346,7 +352,7 @@ module.exports = function init(____0) {
|
|
|
346
352
|
};
|
|
347
353
|
|
|
348
354
|
fsm.isImage = function (extname) {
|
|
349
|
-
if (extname
|
|
355
|
+
if (extname.contains('png|jpg|jpeg|bmp|ico|webp|gif')) {
|
|
350
356
|
return true;
|
|
351
357
|
}
|
|
352
358
|
return false;
|
|
@@ -360,6 +366,7 @@ module.exports = function init(____0) {
|
|
|
360
366
|
}
|
|
361
367
|
|
|
362
368
|
let path = name;
|
|
369
|
+
|
|
363
370
|
if (!____0.isFileExistsSync(path)) {
|
|
364
371
|
path = ____0.path.join(____0.dir, extname, name);
|
|
365
372
|
}
|
package/lib/routing.js
CHANGED
|
@@ -35,7 +35,6 @@ module.exports = function init(____0) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
route.path = route.path || '';
|
|
38
|
-
let encode = ____0.getFileEncode(route.path);
|
|
39
38
|
|
|
40
39
|
// let hash = req.content ? ____0.x0md50x(req.content) : ____0.x0md50x('');
|
|
41
40
|
let last_modified = new Date().toUTCString();
|
|
@@ -63,6 +62,8 @@ module.exports = function init(____0) {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
65
|
+
let encode = ____0.getFileEncode(route.path);
|
|
66
|
+
|
|
66
67
|
if (route.path.endsWith('.css')) {
|
|
67
68
|
res.set(____0.strings[7], 'text/css');
|
|
68
69
|
if (____0.options.cache.enabled) res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.css);
|
|
@@ -302,18 +303,29 @@ module.exports = function init(____0) {
|
|
|
302
303
|
if (typeof r == 'string') {
|
|
303
304
|
r = { name: r };
|
|
304
305
|
}
|
|
306
|
+
if (!r.name.startsWith('/')) {
|
|
307
|
+
r.name = '/' + r.name;
|
|
308
|
+
}
|
|
309
|
+
|
|
305
310
|
for (let i = _0xrrxo.list.length; i--; ) {
|
|
306
|
-
let
|
|
307
|
-
if (r.name && r.method &&
|
|
311
|
+
let oldRoute = _0xrrxo.list[i];
|
|
312
|
+
if (r.name && r.method && oldRoute.name.like(r.name) && oldRoute.method.like(r.method)) {
|
|
313
|
+
_0xrrxo.list.splice(i, 1);
|
|
314
|
+
____0.fsm.off(oldRoute.path);
|
|
315
|
+
} else if (r.name && r.method && oldRoute.nameRaw.like(r.name) && oldRoute.method.like(r.method)) {
|
|
308
316
|
_0xrrxo.list.splice(i, 1);
|
|
309
|
-
____0.fsm.off(
|
|
310
|
-
} else if (r.name &&
|
|
317
|
+
____0.fsm.off(oldRoute.path);
|
|
318
|
+
} else if (r.name && oldRoute.name.like(r.name)) {
|
|
311
319
|
_0xrrxo.list.splice(i, 1);
|
|
312
|
-
____0.fsm.off('*' +
|
|
313
|
-
____0.fsm.off(
|
|
314
|
-
} else if (r.
|
|
320
|
+
____0.fsm.off('*' + oldRoute.name.replace('/', '') + '*');
|
|
321
|
+
____0.fsm.off(oldRoute.path);
|
|
322
|
+
} else if (r.name && oldRoute.nameRaw.like(r.name)) {
|
|
315
323
|
_0xrrxo.list.splice(i, 1);
|
|
316
|
-
____0.fsm.off(
|
|
324
|
+
____0.fsm.off('*' + oldRoute.name.replace('/', '') + '*');
|
|
325
|
+
____0.fsm.off(oldRoute.path);
|
|
326
|
+
} else if (r.method && oldRoute.method.like(r.method)) {
|
|
327
|
+
_0xrrxo.list.splice(i, 1);
|
|
328
|
+
____0.fsm.off(oldRoute.path);
|
|
317
329
|
}
|
|
318
330
|
}
|
|
319
331
|
};
|
|
@@ -336,7 +348,7 @@ module.exports = function init(____0) {
|
|
|
336
348
|
|
|
337
349
|
if (typeof r == 'string') {
|
|
338
350
|
route.name = r.toLowerCase();
|
|
339
|
-
route.
|
|
351
|
+
route.nameRaw = r;
|
|
340
352
|
route.public = ____0.options.public || false;
|
|
341
353
|
route.method = 'GET';
|
|
342
354
|
route.path = null;
|
|
@@ -360,7 +372,7 @@ module.exports = function init(____0) {
|
|
|
360
372
|
}
|
|
361
373
|
} else {
|
|
362
374
|
route.name = r.name.toLowerCase();
|
|
363
|
-
route.
|
|
375
|
+
route.nameRaw = r.name;
|
|
364
376
|
route.public = r.public ?? (____0.options.public || false);
|
|
365
377
|
route.method = r.method || 'GET';
|
|
366
378
|
route.path = r.path || null;
|
|
@@ -396,14 +408,14 @@ module.exports = function init(____0) {
|
|
|
396
408
|
|
|
397
409
|
if (!route.name.startsWith('/')) {
|
|
398
410
|
route.name = '/' + route.name;
|
|
399
|
-
route.
|
|
411
|
+
route.nameRaw = '/' + route.nameRaw;
|
|
400
412
|
}
|
|
401
413
|
|
|
402
414
|
route.name = route.name.replace('//', '/');
|
|
403
|
-
route.
|
|
415
|
+
route.nameRaw = route.nameRaw.replace('//', '/');
|
|
404
416
|
|
|
405
417
|
let arr = route.name.split('/');
|
|
406
|
-
let arr0 = route.
|
|
418
|
+
let arr0 = route.nameRaw.split('/');
|
|
407
419
|
|
|
408
420
|
for (var i = 0; i < arr.length; i++) {
|
|
409
421
|
var s = arr[i];
|
|
@@ -412,17 +424,17 @@ module.exports = function init(____0) {
|
|
|
412
424
|
if (s.startsWith(':')) {
|
|
413
425
|
arr[i] = '*';
|
|
414
426
|
let name = s.replace(':', '');
|
|
415
|
-
let
|
|
427
|
+
let nameRaw = s0.replace(':', '');
|
|
416
428
|
|
|
417
429
|
route.map.push({
|
|
418
430
|
index: i,
|
|
419
431
|
name: name,
|
|
420
432
|
isLower: !1,
|
|
421
433
|
});
|
|
422
|
-
if (name !==
|
|
434
|
+
if (name !== nameRaw) {
|
|
423
435
|
route.map.push({
|
|
424
436
|
index: i,
|
|
425
|
-
name:
|
|
437
|
+
name: nameRaw,
|
|
426
438
|
isLower: !0,
|
|
427
439
|
});
|
|
428
440
|
}
|
|
@@ -454,7 +466,7 @@ module.exports = function init(____0) {
|
|
|
454
466
|
let index = _0xrrxo.list.findIndex((rr) => rr.name == route.name && rr.method == route.method);
|
|
455
467
|
if (index === -1) {
|
|
456
468
|
_0xrrxo.list.push(route);
|
|
457
|
-
} else if (
|
|
469
|
+
} else if (!route.overwrite) {
|
|
458
470
|
if (route.name.like('*api/*')) {
|
|
459
471
|
____0.log('[ Duplicate API ] ' + route.name);
|
|
460
472
|
} else {
|
|
@@ -867,8 +879,15 @@ module.exports = function init(____0) {
|
|
|
867
879
|
}
|
|
868
880
|
};
|
|
869
881
|
|
|
870
|
-
res.html = res.render = function (
|
|
871
|
-
|
|
882
|
+
res.html = res.render = function (file, _data = null, options = {}) {
|
|
883
|
+
let filePath = '';
|
|
884
|
+
if (typeof file === 'object') {
|
|
885
|
+
filePath = file.path;
|
|
886
|
+
options = { ...options, ...file };
|
|
887
|
+
} else {
|
|
888
|
+
filePath = file;
|
|
889
|
+
}
|
|
890
|
+
____0.fsm.getContent(filePath, (content) => {
|
|
872
891
|
if (!content) {
|
|
873
892
|
if (_data && _data.html) {
|
|
874
893
|
return res.status(404).htmlContent(_data.html);
|
|
@@ -877,10 +896,8 @@ module.exports = function init(____0) {
|
|
|
877
896
|
}
|
|
878
897
|
}
|
|
879
898
|
|
|
880
|
-
options = options || {};
|
|
881
899
|
req.content = content;
|
|
882
900
|
req.data = { ...req.data, ..._data };
|
|
883
|
-
req.route = req.route || {};
|
|
884
901
|
req.route = { ...req.route, ...options };
|
|
885
902
|
if (req.route.parser) {
|
|
886
903
|
req.content = ____0.parser(req, res, ____0, req.route).html(req.content);
|
|
@@ -892,103 +909,103 @@ module.exports = function init(____0) {
|
|
|
892
909
|
req.content = req.content.replace(/\r?\n|\r/g, ' ').replace(/\s+/g, ' ');
|
|
893
910
|
}
|
|
894
911
|
|
|
895
|
-
if (
|
|
912
|
+
if (filePath.endsWith('.css')) {
|
|
896
913
|
res.set(____0.strings[7], 'text/css');
|
|
897
914
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
898
915
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.css);
|
|
899
916
|
}
|
|
900
|
-
} else if (
|
|
917
|
+
} else if (filePath.endsWith('.js')) {
|
|
901
918
|
res.set(____0.strings[7], 'application/javascript');
|
|
902
919
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
903
920
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.js);
|
|
904
921
|
}
|
|
905
|
-
} else if (
|
|
922
|
+
} else if (filePath.endsWith('.html')) {
|
|
906
923
|
res.set(____0.strings[7], 'text/html');
|
|
907
924
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
908
925
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.html);
|
|
909
926
|
}
|
|
910
|
-
} else if (
|
|
927
|
+
} else if (filePath.endsWith('.txt')) {
|
|
911
928
|
res.set(____0.strings[7], 'text/plain');
|
|
912
929
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
913
930
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.txt);
|
|
914
931
|
}
|
|
915
|
-
} else if (
|
|
932
|
+
} else if (filePath.endsWith('.json')) {
|
|
916
933
|
res.set(____0.strings[7], 'application/json');
|
|
917
934
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
918
935
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.json);
|
|
919
936
|
}
|
|
920
|
-
} else if (
|
|
937
|
+
} else if (filePath.endsWith('.xml')) {
|
|
921
938
|
res.set(____0.strings[7], 'text/xml');
|
|
922
939
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
923
940
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.xml);
|
|
924
941
|
}
|
|
925
|
-
} else if (
|
|
942
|
+
} else if (filePath.endsWith('.woff2')) {
|
|
926
943
|
res.set(____0.strings[7], 'application/font-woff2');
|
|
927
944
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
928
945
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
929
946
|
}
|
|
930
|
-
} else if (
|
|
947
|
+
} else if (filePath.endsWith('.woff')) {
|
|
931
948
|
res.set(____0.strings[7], 'application/font-woff');
|
|
932
949
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
933
950
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
934
951
|
}
|
|
935
|
-
} else if (
|
|
952
|
+
} else if (filePath.endsWith('.ttf')) {
|
|
936
953
|
res.set(____0.strings[7], 'application/font-ttf');
|
|
937
954
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
938
955
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
939
956
|
}
|
|
940
|
-
} else if (
|
|
957
|
+
} else if (filePath.endsWith('.svg')) {
|
|
941
958
|
res.set(____0.strings[7], 'application/font-svg');
|
|
942
959
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
943
960
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
944
961
|
}
|
|
945
|
-
} else if (
|
|
962
|
+
} else if (filePath.endsWith('.otf')) {
|
|
946
963
|
res.set(____0.strings[7], 'application/font-otf');
|
|
947
964
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
948
965
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
949
966
|
}
|
|
950
|
-
} else if (
|
|
967
|
+
} else if (filePath.endsWith('.eot')) {
|
|
951
968
|
res.set(____0.strings[7], 'application/font-eot');
|
|
952
969
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
953
970
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
|
|
954
971
|
}
|
|
955
|
-
} else if (
|
|
972
|
+
} else if (filePath.endsWith('.gif')) {
|
|
956
973
|
res.set(____0.strings[7], 'image/gif');
|
|
957
974
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
958
975
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
959
976
|
}
|
|
960
|
-
} else if (
|
|
977
|
+
} else if (filePath.endsWith('.png')) {
|
|
961
978
|
res.set(____0.strings[7], 'image/png');
|
|
962
979
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
963
980
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
964
981
|
}
|
|
965
|
-
} else if (
|
|
982
|
+
} else if (filePath.endsWith('.jpg')) {
|
|
966
983
|
res.set(____0.strings[7], 'image/jpg');
|
|
967
984
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
968
985
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
969
986
|
}
|
|
970
|
-
} else if (
|
|
987
|
+
} else if (filePath.endsWith('.jpeg')) {
|
|
971
988
|
res.set(____0.strings[7], 'image/jpeg');
|
|
972
989
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
973
990
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
974
991
|
}
|
|
975
|
-
} else if (
|
|
992
|
+
} else if (filePath.endsWith('.ico')) {
|
|
976
993
|
res.set(____0.strings[7], 'image/ico');
|
|
977
994
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
978
995
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
979
996
|
}
|
|
980
|
-
} else if (
|
|
997
|
+
} else if (filePath.endsWith('.bmp')) {
|
|
981
998
|
res.set(____0.strings[7], 'image/bmp');
|
|
982
999
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
983
1000
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
984
1001
|
}
|
|
985
|
-
} else if (
|
|
1002
|
+
} else if (filePath.endsWith('.webp')) {
|
|
986
1003
|
res.set(____0.strings[7], 'image/webp');
|
|
987
1004
|
if (____0.options.cache.enabled && req.route.cache) {
|
|
988
1005
|
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
|
|
989
1006
|
}
|
|
990
1007
|
}
|
|
991
|
-
res.end(req.content, ____0.getFileEncode(
|
|
1008
|
+
res.end(req.content, ____0.getFileEncode(filePath));
|
|
992
1009
|
});
|
|
993
1010
|
};
|
|
994
1011
|
|
|
@@ -1147,8 +1164,14 @@ module.exports = function init(____0) {
|
|
|
1147
1164
|
|
|
1148
1165
|
for (let i = 0; i < req.route.map.length; i++) {
|
|
1149
1166
|
let map = req.route.map[i];
|
|
1150
|
-
|
|
1151
|
-
|
|
1167
|
+
if (typeof req.urlParser.arr[map.index] === 'string') {
|
|
1168
|
+
try {
|
|
1169
|
+
req.params[map.name] = decodeURIComponent(req.urlParser.arr[map.index].replace(/\+/g, ' '));
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
req.params[map.name] = req.urlParser.arr[map.index].replace(/\+/g, ' ');
|
|
1172
|
+
}
|
|
1173
|
+
req.paramsRaw[map.name] = req.urlParserRaw.arr[map.index];
|
|
1174
|
+
}
|
|
1152
1175
|
}
|
|
1153
1176
|
|
|
1154
1177
|
req.query = req.urlParser.query;
|
|
@@ -1250,14 +1273,14 @@ module.exports = function init(____0) {
|
|
|
1250
1273
|
|
|
1251
1274
|
if (req.urlParser.pathname == '/') {
|
|
1252
1275
|
if (____0.options.help) {
|
|
1253
|
-
res.set('help-eror-message', 'unhandled route root ' + req.urlParser.pathname);
|
|
1276
|
+
res.set('help-eror-message', 'unhandled route root : ' + req.urlParser.pathname);
|
|
1254
1277
|
}
|
|
1255
1278
|
res.htmlContent("<h1 align='center'>Base Route / Not Set</h1>");
|
|
1256
1279
|
return;
|
|
1257
1280
|
}
|
|
1258
1281
|
|
|
1259
1282
|
if (____0.options.help) {
|
|
1260
|
-
res.set('help-eror-message', 'unhandled route help' + req.urlParser.pathname);
|
|
1283
|
+
res.set('help-eror-message', 'unhandled route help : ' + req.urlParser.pathname);
|
|
1261
1284
|
}
|
|
1262
1285
|
|
|
1263
1286
|
if (req.method.toLowerCase().like('options') || req.method.toLowerCase().like('head')) {
|
|
@@ -1267,7 +1290,7 @@ module.exports = function init(____0) {
|
|
|
1267
1290
|
____0.handleNotRoute(req, res);
|
|
1268
1291
|
};
|
|
1269
1292
|
____0.handleNotRoute = function (req, res) {
|
|
1270
|
-
res.set('help-eror-message', 'unhandled route fn' + req.urlParser.pathname);
|
|
1293
|
+
res.set('help-eror-message', 'unhandled route fn : ' + req.urlParser.pathname);
|
|
1271
1294
|
res.status(404).end();
|
|
1272
1295
|
};
|
|
1273
1296
|
____0.servers = [];
|
package/object-options/index.js
CHANGED