pinokiod 1.1.49 → 1.1.50
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/kernel/api/proxy/index.js +16 -10
- package/kernel/api/set/index.js +18 -4
- package/kernel/shells.js +2 -0
- package/package.json +2 -2
- package/kernel/template.js +0 -223
|
@@ -10,16 +10,22 @@ class P {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
try {
|
|
14
|
+
// check proxy
|
|
15
|
+
kernel.api.checkProxy({ uri, name })
|
|
16
|
+
// if exists, don't do anything
|
|
17
|
+
} catch (e) {
|
|
18
|
+
ondata({
|
|
19
|
+
raw: `\r\n[Start proxy] ${req.params.name} ${req.params.uri}\r\n`
|
|
20
|
+
})
|
|
21
|
+
let { name, uri, ...o } = req.params
|
|
22
|
+
console.log("proxy.start", { name, uri, o })
|
|
23
|
+
let response = await kernel.api.startProxy(req.parent.path, req.params.uri, req.params.name, o)
|
|
24
|
+
ondata({
|
|
25
|
+
raw: "Proxy Started\r\n"
|
|
26
|
+
})
|
|
27
|
+
return response
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
async stop (req, ondata, kernel) {
|
|
25
31
|
/*
|
package/kernel/api/set/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const fs = require('fs')
|
|
3
|
-
const set = (old, kv) => {
|
|
3
|
+
const set = async (old, kv, kernel, req, ondata) => {
|
|
4
4
|
for (let key in kv) {
|
|
5
5
|
try {
|
|
6
6
|
if (key.startsWith('[')) {
|
|
@@ -22,6 +22,20 @@ const set = (old, kv) => {
|
|
|
22
22
|
);
|
|
23
23
|
old = fun(old, key, kv[key]);
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// // reserved variable: "url"
|
|
28
|
+
// if (key === "url") {
|
|
29
|
+
// // start proxy
|
|
30
|
+
// ondata({
|
|
31
|
+
// raw: `\r\n[Start proxy] ${kv[key]}\r\n`
|
|
32
|
+
// })
|
|
33
|
+
// let response = await kernel.api.startProxy(req.parent.path, kv[key], "Shared")
|
|
34
|
+
// console.log("Response", response)
|
|
35
|
+
// ondata({
|
|
36
|
+
// raw: `Proxy Started ${JSON.stringify(response)}\r\n`
|
|
37
|
+
// })
|
|
38
|
+
// }
|
|
25
39
|
} catch (e) {
|
|
26
40
|
}
|
|
27
41
|
}
|
|
@@ -64,7 +78,7 @@ module.exports = async (req, ondata, kernel) => {
|
|
|
64
78
|
if (!old) {
|
|
65
79
|
old = {}
|
|
66
80
|
}
|
|
67
|
-
old = set(old, kv)
|
|
81
|
+
old = await set(old, kv, kernel, req, ondata)
|
|
68
82
|
kernel.memory[type][req.parent.path] = old
|
|
69
83
|
|
|
70
84
|
// if (!kernel.memory[type][req.uri]) {
|
|
@@ -112,7 +126,7 @@ module.exports = async (req, ondata, kernel) => {
|
|
|
112
126
|
}
|
|
113
127
|
let kv = req.params.self[relative_filepath]
|
|
114
128
|
|
|
115
|
-
old = set(old, kv)
|
|
129
|
+
old = await set(old, kv, kernel, req, ondata)
|
|
116
130
|
|
|
117
131
|
// write to the filepath
|
|
118
132
|
|
|
@@ -148,7 +162,7 @@ module.exports = async (req, ondata, kernel) => {
|
|
|
148
162
|
|
|
149
163
|
let newkv = req.params.key[host_url]
|
|
150
164
|
|
|
151
|
-
oldkv = set(oldkv, newkv)
|
|
165
|
+
oldkv = await set(oldkv, newkv, kernel, req, ondata)
|
|
152
166
|
|
|
153
167
|
old[host_url] = oldkv
|
|
154
168
|
|
package/kernel/shells.js
CHANGED
|
@@ -170,7 +170,9 @@ class Shells {
|
|
|
170
170
|
stream.matches = rendered_event
|
|
171
171
|
if (typeof handler.return !== "undefined") {
|
|
172
172
|
session.clear()
|
|
173
|
+
console.log("RENDER", { stream })
|
|
173
174
|
let return_value = this.kernel.template.render(handler.return, { event: stream })
|
|
175
|
+
console.log("return_value", return_value)
|
|
174
176
|
|
|
175
177
|
if (session.resolve) {
|
|
176
178
|
session.resolve(return_value)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinokiod",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"http-proxy": "^1.18.1",
|
|
33
33
|
"http-terminator": "^3.2.0",
|
|
34
34
|
"isomorphic-git": "^1.23.0",
|
|
35
|
-
"jimini": "^0.0.
|
|
35
|
+
"jimini": "^0.0.4",
|
|
36
36
|
"jsdom": "^24.0.0",
|
|
37
37
|
"jsonpath-plus": "^7.2.0",
|
|
38
38
|
"key-store": "^1.2.0",
|
package/kernel/template.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
const system = require('systeminformation');
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
const _ = require("lodash")
|
|
5
|
-
class Template {
|
|
6
|
-
constructor(kernel) {
|
|
7
|
-
this.kernel = kernel
|
|
8
|
-
this.platform = kernel.platform
|
|
9
|
-
this.arch = kernel.arch
|
|
10
|
-
this.os = kernel.os
|
|
11
|
-
}
|
|
12
|
-
async init() {
|
|
13
|
-
let g = await system.graphics()
|
|
14
|
-
let gpus
|
|
15
|
-
if (g && g.controllers && g.controllers.length > 0) {
|
|
16
|
-
gpus = g.controllers.map((x) => { return x.vendor.toLowerCase() })
|
|
17
|
-
} else {
|
|
18
|
-
gpus = []
|
|
19
|
-
}
|
|
20
|
-
this.gpus = gpus
|
|
21
|
-
|
|
22
|
-
let is_nvidia = gpus.find(gpu => /nvidia/i.test(gpu))
|
|
23
|
-
let is_amd = gpus.find(gpu => /(amd|advanced micro devices)/i.test(gpu))
|
|
24
|
-
let is_apple = gpus.find(gpu => /apple/i.test(gpu))
|
|
25
|
-
|
|
26
|
-
if (is_nvidia) {
|
|
27
|
-
this.gpu = "nvidia"
|
|
28
|
-
} else if (is_amd) {
|
|
29
|
-
this.gpu = "amd"
|
|
30
|
-
} else if (is_apple) {
|
|
31
|
-
this.gpu = "apple"
|
|
32
|
-
} else if (gpus.length > 0) {
|
|
33
|
-
this.gpu = gpus[0]
|
|
34
|
-
} else {
|
|
35
|
-
this.gpu = "none"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// if (gpus.find((gpu) => { return gpu.includes("nvidia") }) {
|
|
39
|
-
// this.gpu = "nvidia"
|
|
40
|
-
// } else if (gpus.includes("amd") || gpus.includes("advanced micro devices")){
|
|
41
|
-
// this.gpu = "amd"
|
|
42
|
-
// } else if (gpus.includes("apple")) {
|
|
43
|
-
// this.gpu = "apple"
|
|
44
|
-
// } else if (gpus.length > 0) {
|
|
45
|
-
// this.gpu = gpus[0]
|
|
46
|
-
// } else {
|
|
47
|
-
// this.gpu = "none"
|
|
48
|
-
// }
|
|
49
|
-
}
|
|
50
|
-
regex(str) {
|
|
51
|
-
let matches = /^\/(.+)\/([dgimsuy]*)$/gs.exec(str)
|
|
52
|
-
if (!/g/.test(matches[2])) {
|
|
53
|
-
matches[2] += "g" // if g option is not included, include it (need it for matchAll)
|
|
54
|
-
}
|
|
55
|
-
let re = new RegExp(matches[1], matches[2])
|
|
56
|
-
return re
|
|
57
|
-
}
|
|
58
|
-
istemplate(o) {
|
|
59
|
-
let check
|
|
60
|
-
_.forOwn(o, (val, key) => {
|
|
61
|
-
if (typeof key === 'string') {
|
|
62
|
-
let test = /\{\{.*\}\}/g.test(key)
|
|
63
|
-
if (test) {
|
|
64
|
-
check = true
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (typeof val === 'string') {
|
|
68
|
-
let test = /\{\{.*\}\}/g.test(val)
|
|
69
|
-
if (test) {
|
|
70
|
-
check = true
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return check
|
|
75
|
-
}
|
|
76
|
-
flatten(template) {
|
|
77
|
-
let result
|
|
78
|
-
if (typeof template === "string") {
|
|
79
|
-
result = template.replaceAll(/\{\{\{(.*?)\}\}\}/g, '{{$1}}');
|
|
80
|
-
} else if (Array.isArray(template)) {
|
|
81
|
-
result = template.map((item) => {
|
|
82
|
-
return this.flatten(item)
|
|
83
|
-
})
|
|
84
|
-
} else if (typeof template === "object") {
|
|
85
|
-
try {
|
|
86
|
-
if (template.constructor.name === 'Object') {
|
|
87
|
-
try {
|
|
88
|
-
result = {}
|
|
89
|
-
for (let key in template) {
|
|
90
|
-
let flattenedKey = this.flatten(key)
|
|
91
|
-
let flattenedVal = this.flatten(template[key])
|
|
92
|
-
if (flattenedKey !== null && flattenedKey !== false) {
|
|
93
|
-
result[flattenedKey] = flattenedVal;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} catch (e) {
|
|
97
|
-
result = template
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
result = template
|
|
101
|
-
}
|
|
102
|
-
} catch (e2) {
|
|
103
|
-
result = template
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
result = template
|
|
107
|
-
}
|
|
108
|
-
return result
|
|
109
|
-
}
|
|
110
|
-
render(template, vars) {
|
|
111
|
-
let result
|
|
112
|
-
|
|
113
|
-
// CASE 1. String type => can be a regular string or a template string
|
|
114
|
-
if (typeof template === "string") {
|
|
115
|
-
|
|
116
|
-
if (/^\{\{\{(.+)\}\}\}$/g.test(template)) {
|
|
117
|
-
// CASE 1.0. {{{ }}} raw expression => don't parse
|
|
118
|
-
return template
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
else if (/^\{\{.+\}\}$/g.test(template)) {
|
|
123
|
-
// CASE 1.1. the template expression is a pure template (starts with {{ and ends with }})
|
|
124
|
-
|
|
125
|
-
// Example:
|
|
126
|
-
// "{{buf}}" where buf is a Buffer object
|
|
127
|
-
// "{{items}}" where items is an Array
|
|
128
|
-
// "{{int}}" where the int is an integer
|
|
129
|
-
|
|
130
|
-
// get only the variables out
|
|
131
|
-
let v = template.slice(2, -2)
|
|
132
|
-
let r = this.raw_get(v, vars)
|
|
133
|
-
return r
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// CASE 1.2. if the template expression is part of a string "... {{ .. }} ..." => can only be string
|
|
137
|
-
else {
|
|
138
|
-
try {
|
|
139
|
-
const pattern = /{{(.*?)}}/g;
|
|
140
|
-
const matches = [...template.matchAll(pattern)].map((x) => { return x[1] })
|
|
141
|
-
if (matches && matches.length > 0) {
|
|
142
|
-
let vals = []
|
|
143
|
-
for(let v of matches) {
|
|
144
|
-
let val = this.raw_get(v, vars)
|
|
145
|
-
vals.push({
|
|
146
|
-
key: "{{" + v + "}}",
|
|
147
|
-
val
|
|
148
|
-
})
|
|
149
|
-
}
|
|
150
|
-
let res = template
|
|
151
|
-
for(let val of vals) {
|
|
152
|
-
res = res.replaceAll(val.key, val.val)
|
|
153
|
-
}
|
|
154
|
-
return res
|
|
155
|
-
} else {
|
|
156
|
-
return template
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
} catch (e) {
|
|
160
|
-
result = template
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
// Case 2: Array
|
|
166
|
-
else if (Array.isArray(template)) {
|
|
167
|
-
result = []
|
|
168
|
-
for(let item of template) {
|
|
169
|
-
let renderedVal = this.render(item, vars);
|
|
170
|
-
if (typeof renderedVal !== "undefined") {
|
|
171
|
-
result.push(renderedVal)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// Case 2: the template is an object => need to traverse further
|
|
176
|
-
else if (typeof template === "object") {
|
|
177
|
-
try {
|
|
178
|
-
if (template.constructor.name === 'Object') {
|
|
179
|
-
try {
|
|
180
|
-
result = {}
|
|
181
|
-
for (let key in template) {
|
|
182
|
-
let renderedKey = this.render(key, vars);
|
|
183
|
-
let renderedVal = this.render(template[key], vars);
|
|
184
|
-
if (renderedKey !== null && renderedKey !== false) {
|
|
185
|
-
result[renderedKey] = renderedVal;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
} catch (e) {
|
|
189
|
-
console.log("template render log [1]", e)
|
|
190
|
-
result = template
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
result = template
|
|
194
|
-
}
|
|
195
|
-
} catch (e2) {
|
|
196
|
-
console.log("template render log [2]", e2)
|
|
197
|
-
result = template
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Case 3: terminal node => can just use the value
|
|
202
|
-
else {
|
|
203
|
-
result = template
|
|
204
|
-
}
|
|
205
|
-
return result
|
|
206
|
-
}
|
|
207
|
-
raw_get(o, vars) {
|
|
208
|
-
let fun = new Function("uri", "cwd", "key", "local", "global", "self", "input", "current", "next", "event", "_", "os", "path", "system", "pip", "platform", "arch", "gpu", "gpus", "kernel", `return ${o}`)
|
|
209
|
-
try {
|
|
210
|
-
let response = fun(vars.uri, vars.cwd, vars.key, vars.local, vars.global, vars.self, vars.input, vars.current, vars.next, vars.event, _, this.os, path, system, vars.pip, this.platform, this.arch, this.gpu, this.gpus, this.kernel)
|
|
211
|
-
if (typeof response === "undefined") {
|
|
212
|
-
return `{{${o}}}`
|
|
213
|
-
} else {
|
|
214
|
-
return response
|
|
215
|
-
}
|
|
216
|
-
} catch (e) {
|
|
217
|
-
console.log("ERROR", e)
|
|
218
|
-
return `{{${o}}}`
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
module.exports = Template
|