pinokiod 1.1.49 → 1.1.51
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 +18 -10
- package/kernel/api/set/index.js +18 -4
- package/kernel/shells.js +2 -0
- package/package.json +3 -2
- package/server/index.js +10 -0
- package/server/public/style.css +21 -0
- package/server/views/index.ejs +19 -0
- package/kernel/template.js +0 -223
|
@@ -10,16 +10,24 @@ 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
|
+
|
|
25
|
+
ondata({
|
|
26
|
+
raw: `Proxy Started ${JSON.stringify(response)}\r\n`
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return response
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
async stop (req, ondata, kernel) {
|
|
25
33
|
/*
|
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.51",
|
|
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",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"open": "8.4.2",
|
|
48
48
|
"pdrive": "^0.0.23",
|
|
49
49
|
"portfinder": "^1.0.32",
|
|
50
|
+
"qrcode": "^1.5.3",
|
|
50
51
|
"random-useragent": "^0.5.0",
|
|
51
52
|
"rimraf": "^5.0.0",
|
|
52
53
|
"sanitize-filename": "^1.6.3",
|
package/server/index.js
CHANGED
|
@@ -14,6 +14,8 @@ const os = require('os')
|
|
|
14
14
|
const { fork } = require('child_process');
|
|
15
15
|
const semver = require('semver')
|
|
16
16
|
const fse = require('fs-extra')
|
|
17
|
+
const QRCode = require('qrcode')
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
const git = require('isomorphic-git')
|
|
19
21
|
const http = require('isomorphic-git/http/node')
|
|
@@ -1011,8 +1013,16 @@ class Server {
|
|
|
1011
1013
|
|
|
1012
1014
|
let pinokio_proxy = this.kernel.api.proxies["/"]
|
|
1013
1015
|
|
|
1016
|
+
console.log("pinokio_proxy", pinokio_proxy)
|
|
1017
|
+
let qr = null
|
|
1018
|
+
if (pinokio_proxy && pinokio_proxy.length > 0) {
|
|
1019
|
+
qr = await QRCode.toDataURL(pinokio_proxy[0].proxy)
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
|
|
1014
1023
|
res.render("index", {
|
|
1015
1024
|
proxy: pinokio_proxy[0],
|
|
1025
|
+
qr,
|
|
1016
1026
|
error: error,
|
|
1017
1027
|
logo: this.logo,
|
|
1018
1028
|
// memory: mem,
|
package/server/public/style.css
CHANGED
|
@@ -81,6 +81,27 @@ footer .toggle-expand {
|
|
|
81
81
|
footer pre {
|
|
82
82
|
background: none !important;
|
|
83
83
|
}
|
|
84
|
+
.swal2-popup.min-popup a {
|
|
85
|
+
outline: none;
|
|
86
|
+
}
|
|
87
|
+
.swal2-popup.min-popup img {
|
|
88
|
+
margin: 10px 0;
|
|
89
|
+
}
|
|
90
|
+
.swal2-popup.min-popup {
|
|
91
|
+
width: 300px;
|
|
92
|
+
text-align: center !important;
|
|
93
|
+
padding: 30px 0 !important;
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
}
|
|
96
|
+
.swal2-title.min-title {
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
text-align: center !important;
|
|
99
|
+
padding: 0 0 !important;
|
|
100
|
+
}
|
|
101
|
+
.min-modal {
|
|
102
|
+
text-align: center;
|
|
103
|
+
font-size: 14px;
|
|
104
|
+
}
|
|
84
105
|
.wait-modal {
|
|
85
106
|
padding: 20px;
|
|
86
107
|
text-align: center;
|
package/server/views/index.ejs
CHANGED
|
@@ -119,7 +119,10 @@ header .runner {
|
|
|
119
119
|
<% if (ishome) { %>
|
|
120
120
|
<div class='nav-btns'>
|
|
121
121
|
<a class='btn2' id='explore'><div><i class="fa-solid fa-globe"></i></div><div>Discover</div></a>
|
|
122
|
+
<a id='wifi' data-proxy="<%=proxy.proxy%>" class='btn2'><div><i class="fa-solid fa-wifi"></i></div><div>WiFi</div></a>
|
|
123
|
+
<!--
|
|
122
124
|
<a class='btn2' href="<%=proxy.proxy%>" target="_blank"><div><i class="fa-solid fa-wifi"></i></div><div>WiFi</div></a>
|
|
125
|
+
-->
|
|
123
126
|
<a class='btn2' id='report'><div><i class="fa-solid fa-bug"></i></div><div>Report Bug</div></a>
|
|
124
127
|
<a class='btn2' href='https://discord.gg/TQdNwadtE4' target="_blank"><div><i class="fa-brands fa-discord"></i></div><div>Discord</div></a>
|
|
125
128
|
<a class='btn2' href='https://twitter.com/cocktailpeanut' target="_blank"><div><i class="fa-brands fa-twitter"></i></div><div>Twitter</div></a>
|
|
@@ -618,6 +621,22 @@ document.addEventListener("click", (e) => {
|
|
|
618
621
|
target.closest(".line").classList.add("selected")
|
|
619
622
|
}
|
|
620
623
|
})
|
|
624
|
+
<% if (qr) { %>
|
|
625
|
+
document.querySelector("#wifi").addEventListener("click", async (e) => {
|
|
626
|
+
await Swal.fire({
|
|
627
|
+
title: "Wifi Sharing",
|
|
628
|
+
customClass: {
|
|
629
|
+
popup: "min-popup",
|
|
630
|
+
title: "min-title"
|
|
631
|
+
},
|
|
632
|
+
showConfirmButton: false,
|
|
633
|
+
html: `<div class='min-modal'>
|
|
634
|
+
<div><img src="<%=qr%>"></div>
|
|
635
|
+
<a href="<%=proxy.proxy%>" target="_blank"><%=proxy.proxy%></a>
|
|
636
|
+
</div>`
|
|
637
|
+
})
|
|
638
|
+
})
|
|
639
|
+
<% } %>
|
|
621
640
|
<% } %>
|
|
622
641
|
|
|
623
642
|
</script>
|
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
|