telos-server 1.0.12 → 1.0.13
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/package.json +1 -1
- package/serverUtils.js +58 -24
- package/telosEngine.js +40 -0
- package/telosRouter.js +37 -0
- package/telosServer.json +6 -0
package/package.json
CHANGED
package/serverUtils.js
CHANGED
|
@@ -30,6 +30,33 @@ var fileTypes = [
|
|
|
30
30
|
'mp4'
|
|
31
31
|
];
|
|
32
32
|
|
|
33
|
+
function getAllFiles(directory) {
|
|
34
|
+
|
|
35
|
+
let items = { };
|
|
36
|
+
|
|
37
|
+
if(Array.isArray(directory)) {
|
|
38
|
+
|
|
39
|
+
directory.forEach(value => {
|
|
40
|
+
Object.assign(items, getAllFiles(value));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return items;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fs.readdirSync(directory).forEach(value => {
|
|
47
|
+
|
|
48
|
+
value = directory + path.sep + value;
|
|
49
|
+
|
|
50
|
+
if(fs.statSync(value).isFile())
|
|
51
|
+
items[value] = getFileData(value);
|
|
52
|
+
|
|
53
|
+
else
|
|
54
|
+
Object.assign(items, getAllFiles(value));
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return items;
|
|
58
|
+
}
|
|
59
|
+
|
|
33
60
|
function getFile(uri, directories) {
|
|
34
61
|
|
|
35
62
|
try {
|
|
@@ -47,37 +74,42 @@ function getFile(uri, directories) {
|
|
|
47
74
|
directories
|
|
48
75
|
).map(file => {
|
|
49
76
|
|
|
50
|
-
let
|
|
51
|
-
file.substring(file.lastIndexOf(".") + 1) : null;
|
|
77
|
+
let data = getFileData(file);
|
|
52
78
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
meta: file.split(/[\/\\]/).map(item =>
|
|
57
|
-
item.split(".").slice(1).reduce(
|
|
58
|
-
(value, item) => {
|
|
79
|
+
return data.meta.private == null ? data : null;
|
|
80
|
+
})[0];
|
|
81
|
+
}
|
|
59
82
|
|
|
60
|
-
|
|
83
|
+
catch(error) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
61
87
|
|
|
62
|
-
|
|
88
|
+
function getFileData(file) {
|
|
63
89
|
|
|
64
|
-
|
|
65
|
-
|
|
90
|
+
let type = file.includes(".") ?
|
|
91
|
+
file.substring(file.lastIndexOf(".") + 1) : null;
|
|
66
92
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
93
|
+
return {
|
|
94
|
+
file: file,
|
|
95
|
+
folder: fs.lstatSync(file).isDirectory(),
|
|
96
|
+
meta: file.split(/[\/\\]/).map(item =>
|
|
97
|
+
item.split(".").slice(1).reduce(
|
|
98
|
+
(value, item) => {
|
|
74
99
|
|
|
75
|
-
|
|
76
|
-
})[0];
|
|
77
|
-
}
|
|
100
|
+
item = item.split("-");
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
|
|
102
|
+
let key = item[0].toLowerCase()
|
|
103
|
+
|
|
104
|
+
if(key != type)
|
|
105
|
+
value[key] = item.slice(1).join("-");
|
|
106
|
+
|
|
107
|
+
return value;
|
|
108
|
+
},
|
|
109
|
+
{ }
|
|
110
|
+
)
|
|
111
|
+
).reduce((value, item) => Object.assign(value, item), { }),
|
|
112
|
+
type: type
|
|
81
113
|
}
|
|
82
114
|
}
|
|
83
115
|
|
|
@@ -242,7 +274,9 @@ function processRequest(request, protocol, callback) {
|
|
|
242
274
|
module.exports = {
|
|
243
275
|
extensionTypes,
|
|
244
276
|
fileTypes,
|
|
277
|
+
getAllFiles,
|
|
245
278
|
getFile,
|
|
279
|
+
getFileData,
|
|
246
280
|
getFiles,
|
|
247
281
|
isHTTPJSON,
|
|
248
282
|
processRequest
|
package/telosEngine.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var busNet = use("bus-net");
|
|
2
|
+
|
|
3
|
+
var telosEngine = {
|
|
4
|
+
initialization: null,
|
|
5
|
+
interval: null,
|
|
6
|
+
query: (packet) => {
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
|
|
10
|
+
packet = JSON.parse(packet);
|
|
11
|
+
|
|
12
|
+
if(packet.tags.includes("telos-origin") &&
|
|
13
|
+
packet.tags.includes("initialize")) {
|
|
14
|
+
|
|
15
|
+
telosEngine.initialization = packet;
|
|
16
|
+
|
|
17
|
+
telosEngine.interval = setInterval(
|
|
18
|
+
() => { busNet.call(`{"tags":["telos-engine"]}`); },
|
|
19
|
+
1000 / 60
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if(packet.tags.includes("telos-configuration") &&
|
|
26
|
+
packet.tags.length == 1) {
|
|
27
|
+
|
|
28
|
+
return telosEngine.initialization = packet;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
catch(error) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
tags: ["telos-origin", "telos-engine"]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if(typeof module == "object")
|
|
40
|
+
module.exports = telosEngine;
|
package/telosRouter.js
CHANGED
|
@@ -16,6 +16,42 @@ var telosRouter = {
|
|
|
16
16
|
|
|
17
17
|
packet = JSON.parse(packet);
|
|
18
18
|
|
|
19
|
+
if(packet.tags != null) {
|
|
20
|
+
|
|
21
|
+
if(packet.tags.length == 1 &&
|
|
22
|
+
packet.tags[0] == "telos-engine") {
|
|
23
|
+
|
|
24
|
+
telosRouter.tasks = telosRouter.tasks != null ?
|
|
25
|
+
telosRouter.tasks :
|
|
26
|
+
Object.values(
|
|
27
|
+
serverUtils.getAllFiles(
|
|
28
|
+
telosRouter.config.directories
|
|
29
|
+
)
|
|
30
|
+
).filter(
|
|
31
|
+
item => item != null
|
|
32
|
+
).filter(
|
|
33
|
+
item =>
|
|
34
|
+
Object.keys(item.meta).includes("task") &&
|
|
35
|
+
item.type == "js"
|
|
36
|
+
).map(
|
|
37
|
+
item => item.file
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
telosRouter.tasks.forEach(item => {
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
use(item)();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
catch(error) {
|
|
47
|
+
console.log(error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
19
55
|
let middleware = [];
|
|
20
56
|
|
|
21
57
|
apint.queryUtilities(
|
|
@@ -119,6 +155,7 @@ var telosRouter = {
|
|
|
119
155
|
`
|
|
120
156
|
};
|
|
121
157
|
},
|
|
158
|
+
tasks: null,
|
|
122
159
|
tags: ["telos-origin", "telos-router"]
|
|
123
160
|
};
|
|
124
161
|
|