pinokiod 1.3.71 → 1.3.73
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/cloudflare/index.js +9 -2
- package/kernel/api/env/index.js +47 -2
- package/kernel/api/fs/index.js +1 -1
- package/kernel/api/index.js +5 -0
- package/kernel/api/local/index.js +1 -1
- package/kernel/api/proxy/index.js +9 -0
- package/kernel/environment.js +201 -101
- package/kernel/index.js +3 -5
- package/kernel/shell.js +1 -3
- package/kernel/util.js +31 -34
- package/package.json +1 -1
- package/server/index.js +20 -33
- package/server/socket.js +0 -2
- package/server/views/browser-experimental.ejs +3 -0
- package/server/views/explore.ejs +2 -2
- package/server/views/fullscreen_editor.ejs +1 -8
|
@@ -12,7 +12,6 @@ class C {
|
|
|
12
12
|
|
|
13
13
|
=> cloudflared tunnel --url http://localhost:8080
|
|
14
14
|
*/
|
|
15
|
-
console.log("TUNNEL", req)
|
|
16
15
|
const message = `cloudflared tunnel --url ${req.params.uri}`
|
|
17
16
|
let params = {
|
|
18
17
|
id: message,
|
|
@@ -26,7 +25,6 @@ class C {
|
|
|
26
25
|
if (req.cwd) options.cwd = req.cwd
|
|
27
26
|
if (req.parent && req.parent.path) options.group = req.parent.path
|
|
28
27
|
let pattern = /(https:.+?trycloudflare\.com)/
|
|
29
|
-
console.log("params", params)
|
|
30
28
|
let cloudflare_url = await new Promise((resolve, reject) => {
|
|
31
29
|
kernel.shell.start(params, options, (e) => {
|
|
32
30
|
ondata(e)
|
|
@@ -52,6 +50,15 @@ class C {
|
|
|
52
50
|
});
|
|
53
51
|
})
|
|
54
52
|
|
|
53
|
+
/***************************************************
|
|
54
|
+
Expose local variabl
|
|
55
|
+
|
|
56
|
+
local.$share := {
|
|
57
|
+
cloudflare: {
|
|
58
|
+
<original_url>: <cloudflare_url>
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
***************************************************/
|
|
55
62
|
if (!kernel.memory.local[req.parent.path].$share) {
|
|
56
63
|
kernel.memory.local[req.parent.path].$share = {}
|
|
57
64
|
}
|
package/kernel/api/env/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path')
|
|
1
2
|
const set = require("../set")
|
|
2
3
|
const rm = require("../rm")
|
|
3
4
|
const Environment = require('../../environment')
|
|
@@ -14,9 +15,53 @@ class Env {
|
|
|
14
15
|
}
|
|
15
16
|
*/
|
|
16
17
|
// write to current app folder's ENVIRONMENT
|
|
18
|
+
let api_path = Util.api_path(req.parent.path, kernel)
|
|
19
|
+
let env_path = path.resolve(api_path, "ENVIRONMENT")
|
|
20
|
+
await Util.update_env(env_path, req.params)
|
|
21
|
+
}
|
|
22
|
+
async switch(req, ondata, kernel) {
|
|
23
|
+
/*
|
|
24
|
+
req := {
|
|
25
|
+
"method": "env.switch",
|
|
26
|
+
"params": {
|
|
27
|
+
<key>: ["true", "false"],
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
req := {
|
|
32
|
+
"method": "env.switch",
|
|
33
|
+
"params": {
|
|
34
|
+
<key>: ["apple", "orange", "grape"],
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
*/
|
|
38
|
+
let api_path = Util.api_path(req.parent.path, kernel)
|
|
39
|
+
let env_path = path.resolve(api_path, "ENVIRONMENT")
|
|
40
|
+
let env = await Environment.get2(req.parent.path, kernel)
|
|
41
|
+
// does the key exist?
|
|
17
42
|
|
|
18
|
-
let
|
|
19
|
-
|
|
43
|
+
let update = {}
|
|
44
|
+
for(let key in req.params) {
|
|
45
|
+
let options = req.params[key]
|
|
46
|
+
if (key in env) {
|
|
47
|
+
// if the key exists, check if the values are one of the options
|
|
48
|
+
let existing_val = env[key]
|
|
49
|
+
if (options.includes(existing_val)) {
|
|
50
|
+
// find the item index
|
|
51
|
+
let existing_index = options.indexOf(existing_val)
|
|
52
|
+
// choose the next option in the array
|
|
53
|
+
let next_index = (existing_index + 1) % options.length
|
|
54
|
+
let next_item = options[next_index]
|
|
55
|
+
update[key] = next_item
|
|
56
|
+
} else {
|
|
57
|
+
// if not one of the options, ignore. must match exactly
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
// if the key doesn't exist, the first item is the default
|
|
61
|
+
update[key] = options[0]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
await Util.update_env(env_path, update)
|
|
20
65
|
}
|
|
21
66
|
}
|
|
22
67
|
module.exports = Env
|
package/kernel/api/fs/index.js
CHANGED
|
@@ -131,7 +131,7 @@ class FS {
|
|
|
131
131
|
|
|
132
132
|
// start with the proces.env => merge pinokio global ENVIRONMENT => merge app ENVIRONMENT
|
|
133
133
|
let default_env = await Environment.get(kernel.homedir)
|
|
134
|
-
let api_path =
|
|
134
|
+
let api_path = Util.api_path(req.parent.path, kernel)
|
|
135
135
|
let api_env = await Environment.get(api_path)
|
|
136
136
|
let current_env = Object.assign(process.env, default_env, api_env)
|
|
137
137
|
|
package/kernel/api/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const Lproxy = require('lproxy')
|
|
|
9
9
|
const { glob, sync, hasMagic } = require('glob-gitignore')
|
|
10
10
|
const fastq = require('fastq')
|
|
11
11
|
const Loader = require("../loader")
|
|
12
|
+
const Environment = require("../environment")
|
|
12
13
|
|
|
13
14
|
class Api {
|
|
14
15
|
constructor(kernel) {
|
|
@@ -534,6 +535,10 @@ class Api {
|
|
|
534
535
|
|
|
535
536
|
this.state = memory
|
|
536
537
|
this.executing = request
|
|
538
|
+
// get fully resolved env
|
|
539
|
+
let env = await Environment.get2(request.path, this.kernel)
|
|
540
|
+
// set template
|
|
541
|
+
this.kernel.template.update(env)
|
|
537
542
|
|
|
538
543
|
// render until `{{ }}` pattern does not exist
|
|
539
544
|
// 1. render once
|
|
@@ -63,7 +63,7 @@ class Local {
|
|
|
63
63
|
}
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
|
-
let api_path =
|
|
66
|
+
let api_path = Util.api_path(req.parent.path, kernel)
|
|
67
67
|
let current_env = await Environment.get(api_path)
|
|
68
68
|
let default_env = await Environment.get(kernel.homedir)
|
|
69
69
|
current_env = Object.assign(process.env, default_env, current_env)
|
|
@@ -40,6 +40,15 @@ class P {
|
|
|
40
40
|
});
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
+
/***************************************************
|
|
44
|
+
Expose local variabl
|
|
45
|
+
|
|
46
|
+
local.$share := {
|
|
47
|
+
local: {
|
|
48
|
+
<original_url>: <cloudflare_url>
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
***************************************************/
|
|
43
52
|
if (!kernel.memory.local[req.parent.path].$share) {
|
|
44
53
|
kernel.memory.local[req.parent.path].$share = {}
|
|
45
54
|
}
|
package/kernel/environment.js
CHANGED
|
@@ -1,103 +1,157 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const fs = require('fs')
|
|
3
|
-
const
|
|
3
|
+
const Util = require('./util')
|
|
4
4
|
const ENVS = [{
|
|
5
|
-
type: "
|
|
6
|
-
key: "HF_HOME",
|
|
7
|
-
}, {
|
|
8
|
-
type: "cache_folder",
|
|
9
|
-
key: "TORCH_HOME",
|
|
10
|
-
}, {
|
|
11
|
-
type: "cache_folder",
|
|
5
|
+
type: ["system"],
|
|
12
6
|
key: "HOMEBREW_CACHE",
|
|
7
|
+
hidden: true,
|
|
8
|
+
val: "./cache/HOMEBREW_CACHE"
|
|
13
9
|
}, {
|
|
14
|
-
type: "
|
|
10
|
+
type: ["system"],
|
|
15
11
|
key: "XDG_CACHE_HOME",
|
|
12
|
+
hidden: true,
|
|
13
|
+
val: "./cache/XDG_CACHE_HOME"
|
|
16
14
|
}, {
|
|
17
|
-
type: "
|
|
15
|
+
type: ["system"],
|
|
18
16
|
key: "PIP_CACHE_DIR",
|
|
17
|
+
hidden: true,
|
|
18
|
+
val: "./cache/PIP_CACHE_DIR"
|
|
19
19
|
}, {
|
|
20
|
-
type: "
|
|
20
|
+
type: ["system"],
|
|
21
21
|
key: "PIP_TMPDIR",
|
|
22
|
+
hidden: true,
|
|
23
|
+
val: "./cache/PIP_TMPDIR"
|
|
22
24
|
}, {
|
|
23
|
-
type: "
|
|
25
|
+
type: ["system"],
|
|
24
26
|
key: "TMPDIR",
|
|
27
|
+
hidden: true,
|
|
28
|
+
val: "./cache/TMPDIR"
|
|
25
29
|
}, {
|
|
26
|
-
type: "
|
|
30
|
+
type: ["system"],
|
|
27
31
|
key: "TEMP",
|
|
32
|
+
hidden: true,
|
|
33
|
+
val: "./cache/TEMP"
|
|
28
34
|
}, {
|
|
29
|
-
type: "
|
|
35
|
+
type: ["system"],
|
|
30
36
|
key: "TMP",
|
|
37
|
+
hidden: true,
|
|
38
|
+
val: "./cache/TMP"
|
|
31
39
|
}, {
|
|
32
|
-
type: "
|
|
40
|
+
type: ["system"],
|
|
33
41
|
key: "XDG_DATA_HOME",
|
|
42
|
+
hidden: true,
|
|
43
|
+
val: "./cache/XDG_DATA_HOME"
|
|
34
44
|
}, {
|
|
35
|
-
type: "
|
|
45
|
+
type: ["system"],
|
|
36
46
|
key: "XDG_CONFIG_HOME",
|
|
47
|
+
hidden: true,
|
|
48
|
+
val: "./cache/XDG_CONFIG_HOME"
|
|
37
49
|
}, {
|
|
38
|
-
type: "
|
|
50
|
+
type: ["system"],
|
|
39
51
|
key: "XDG_STATE_HOME",
|
|
52
|
+
hidden: true,
|
|
53
|
+
val: "./cache/XDG_STATE_HOME"
|
|
40
54
|
}, {
|
|
41
|
-
type: "
|
|
42
|
-
key: "GRADIO_TEMP_DIR",
|
|
43
|
-
}, {
|
|
55
|
+
type: ["system"],
|
|
44
56
|
key: "PIP_CONFIG_FILE",
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
57
|
+
hidden: true,
|
|
58
|
+
val: "./pipconfig"
|
|
48
59
|
}, {
|
|
60
|
+
type: ["system"],
|
|
49
61
|
key: "CONDARC",
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
62
|
+
hidden: true,
|
|
63
|
+
val: "./condarc"
|
|
53
64
|
}, {
|
|
65
|
+
type: ["system"],
|
|
54
66
|
key: "PS1",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
hidden: true,
|
|
68
|
+
val: "<<PINOKIO SHELL>> "
|
|
69
|
+
}, {
|
|
70
|
+
type: ["system"],
|
|
71
|
+
key: "GRADIO_ANALYTICS_ENABLED",
|
|
72
|
+
val: "False"
|
|
73
|
+
}, {
|
|
74
|
+
type: ["system"],
|
|
75
|
+
key: "GRADIO_ALLOWED_PATHS",
|
|
76
|
+
val: "./",
|
|
77
|
+
comment: [
|
|
78
|
+
"##########################################################################",
|
|
79
|
+
"#",
|
|
80
|
+
"# GRADIO_ALLOWED_PATHS",
|
|
81
|
+
"#",
|
|
82
|
+
"# This allows every Gradio app installed under Pinokio to serve files",
|
|
83
|
+
"# outside of each app's root folder, which is useful for many cases.",
|
|
84
|
+
"# Do not touch this unless you want to add additional paths",
|
|
85
|
+
"#",
|
|
86
|
+
"##########################################################################",
|
|
87
|
+
],
|
|
58
88
|
}, {
|
|
89
|
+
type: ["system"],
|
|
59
90
|
key: "PINOKIO_SHARE_VAR",
|
|
60
|
-
val:
|
|
61
|
-
|
|
62
|
-
|
|
91
|
+
val: "url",
|
|
92
|
+
comment: [
|
|
93
|
+
"##########################################################################",
|
|
94
|
+
"#",
|
|
95
|
+
"# PINOKIO_SHARE_VAR",
|
|
96
|
+
"#",
|
|
97
|
+
"# When you set this local variable from any script, it will trigger Pinokio",
|
|
98
|
+
"# share actions (local sharing, cloudflare, ...)",
|
|
99
|
+
"#",
|
|
100
|
+
"# You can customize whether to avoid this using PINOKIO_SHARE_CLOUDFLARE",
|
|
101
|
+
"# and PINOKIO_SHARE_LOCAL",
|
|
102
|
+
"#",
|
|
103
|
+
"##########################################################################",
|
|
104
|
+
],
|
|
63
105
|
}, {
|
|
64
|
-
type: "
|
|
106
|
+
type: ["system"],
|
|
65
107
|
key: "PINOKIO_DRIVE",
|
|
66
|
-
val:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
108
|
+
val: "./drive",
|
|
109
|
+
comment: [
|
|
110
|
+
"##########################################################################",
|
|
111
|
+
"#",
|
|
112
|
+
"# PINOKIO_DRIVE",
|
|
113
|
+
"#",
|
|
114
|
+
"# The virtual drive path.",
|
|
115
|
+
"# Change it if you want to use a different path.",
|
|
116
|
+
"# You can even enter an absolute path to use a folder outside of pinokio",
|
|
117
|
+
"# or an entirely different disk drive",
|
|
118
|
+
"#",
|
|
119
|
+
"##########################################################################",
|
|
120
|
+
],
|
|
74
121
|
}, {
|
|
122
|
+
type: ["system"],
|
|
75
123
|
key: "PINOKIO_PORT",
|
|
76
|
-
val:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
val: "80",
|
|
125
|
+
comment: [
|
|
126
|
+
"##########################################################################",
|
|
127
|
+
"#",
|
|
128
|
+
"# PINOKIO_PORT",
|
|
129
|
+
"#",
|
|
130
|
+
"# The server port Pinokio will use. By default it's 80 but you can",
|
|
131
|
+
"# Change it to anything else",
|
|
132
|
+
"#",
|
|
133
|
+
"##########################################################################",
|
|
134
|
+
],
|
|
135
|
+
}, {
|
|
136
|
+
type: ["system", "app"],
|
|
137
|
+
key: "GRADIO_TEMP_DIR",
|
|
138
|
+
val: "./cache/GRADIO_TEMP_DIR",
|
|
139
|
+
comment: [
|
|
140
|
+
"##########################################################################",
|
|
141
|
+
"#",
|
|
142
|
+
"# GRADIO_TEMP_DIR",
|
|
143
|
+
"# All the files uploaded through gradio goes here.",
|
|
144
|
+
"#",
|
|
145
|
+
"# Delete this line to store the files under PINOKIO_HOME/cache/GRADIO_TEMPDIR",
|
|
146
|
+
"# or change the path if you want to use a different path",
|
|
147
|
+
"#",
|
|
148
|
+
"##########################################################################",
|
|
149
|
+
],
|
|
150
|
+
}, {
|
|
151
|
+
type: ["system", "app"],
|
|
152
|
+
key: "HF_HOME",
|
|
153
|
+
val: "./cache/HF_HOME",
|
|
154
|
+
comment: [
|
|
101
155
|
"##########################################################################",
|
|
102
156
|
"#",
|
|
103
157
|
"# HF_HOME",
|
|
@@ -110,8 +164,12 @@ const APP_ENV = () => {
|
|
|
110
164
|
"# huggingface files under PINOKIO_HOME/cache/HF_HOME without redundancy.",
|
|
111
165
|
"#",
|
|
112
166
|
"##########################################################################",
|
|
113
|
-
|
|
114
|
-
|
|
167
|
+
],
|
|
168
|
+
}, {
|
|
169
|
+
type: ["system", "app"],
|
|
170
|
+
key: "TORCH_HOME",
|
|
171
|
+
val: "./cache/TORCH_HOME",
|
|
172
|
+
comment: [
|
|
115
173
|
"##########################################################################",
|
|
116
174
|
"#",
|
|
117
175
|
"# TORCH_HOME",
|
|
@@ -123,35 +181,36 @@ const APP_ENV = () => {
|
|
|
123
181
|
"# torch hub files under PINOKIO_HOME/cache/TORCH_HOME without redundancy.",
|
|
124
182
|
"#",
|
|
125
183
|
"##########################################################################",
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"#",
|
|
133
|
-
"# Delete this line to store the files under PINOKIO_HOME/cache/GRADIO_TEMPDIR",
|
|
134
|
-
"# or change the path if you want to use a different path",
|
|
135
|
-
"#",
|
|
136
|
-
"##########################################################################",
|
|
137
|
-
"GRADIO_TEMP_DIR=cache/GRADIO_TEMP_DIR",
|
|
138
|
-
"",
|
|
184
|
+
],
|
|
185
|
+
}, {
|
|
186
|
+
type: ["system", "app"],
|
|
187
|
+
key: "PINOKIO_SHARE_LOCAL",
|
|
188
|
+
val: "false",
|
|
189
|
+
comment: [
|
|
139
190
|
"##########################################################################",
|
|
140
191
|
"#",
|
|
141
192
|
"# PINOKIO_SHARE_LOCAL",
|
|
142
193
|
"# Set this variable to true to share the app on the local network.",
|
|
143
194
|
"#",
|
|
144
195
|
"##########################################################################",
|
|
145
|
-
|
|
146
|
-
|
|
196
|
+
],
|
|
197
|
+
}, {
|
|
198
|
+
type: ["system", "app"],
|
|
199
|
+
key: "PINOKIO_SHARE_CLOUDFLARE",
|
|
200
|
+
val: "false",
|
|
201
|
+
comment: [
|
|
147
202
|
"##########################################################################",
|
|
148
203
|
"#",
|
|
149
204
|
"# PINOKIO_SHARE_CLOUDFLARE",
|
|
150
205
|
"# Set this variable to share the app publicly via cloudflare tunnel.",
|
|
151
206
|
"#",
|
|
152
207
|
"##########################################################################",
|
|
153
|
-
|
|
154
|
-
|
|
208
|
+
]
|
|
209
|
+
}, {
|
|
210
|
+
type: ["system", "app"],
|
|
211
|
+
key: "PINOKIO_SCRIPT_DEFAULT",
|
|
212
|
+
val: "true",
|
|
213
|
+
comment: [
|
|
155
214
|
"##########################################################################",
|
|
156
215
|
"#",
|
|
157
216
|
"# PINOKIO_SCRIPT_DEFAULT",
|
|
@@ -159,36 +218,77 @@ const APP_ENV = () => {
|
|
|
159
218
|
"# will NOT automatically run",
|
|
160
219
|
"#",
|
|
161
220
|
"##########################################################################",
|
|
162
|
-
"PINOKIO_SCRIPT_DEFAULT=true",
|
|
163
221
|
]
|
|
164
|
-
|
|
222
|
+
}];
|
|
223
|
+
//const ENV = (homedir) => {
|
|
224
|
+
// const lines = ENVS.map((e) => {
|
|
225
|
+
// if (e.type) {
|
|
226
|
+
// if (e.type === "cache_folder") {
|
|
227
|
+
// return `${e.key}=${path.resolve(homedir, "cache", e.key)}`
|
|
228
|
+
// }
|
|
229
|
+
// } else {
|
|
230
|
+
// if (e.val) {
|
|
231
|
+
// return `${e.key}=${e.val(homedir)}`
|
|
232
|
+
// }
|
|
233
|
+
// }
|
|
234
|
+
// })
|
|
235
|
+
// return lines.join("\n")
|
|
236
|
+
//}
|
|
237
|
+
|
|
238
|
+
// type := system|app
|
|
239
|
+
const ENV = (type) => {
|
|
240
|
+
return ENVS.filter((e) => {
|
|
241
|
+
return e.type.includes(type)
|
|
242
|
+
}).map((e) => {
|
|
243
|
+
let comment = ""
|
|
244
|
+
if (e.comment && Array.isArray(e.comment)) {
|
|
245
|
+
comment = "\n" + e.comment.join("\n") + "\n"
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
let kv
|
|
249
|
+
if (typeof e.val === "function") {
|
|
250
|
+
kv = `${e.key}=${e.val(type)}`
|
|
251
|
+
} else {
|
|
252
|
+
kv = `${e.key}=${e.val}`
|
|
253
|
+
}
|
|
254
|
+
return comment + kv
|
|
255
|
+
}).join("\n")
|
|
165
256
|
}
|
|
166
257
|
const init_folders = async (homedir) => {
|
|
167
|
-
// get the environment object from homedir
|
|
168
258
|
const current_env = await get(homedir)
|
|
169
|
-
|
|
170
|
-
// filter out only the folder keys
|
|
171
|
-
|
|
172
|
-
// create folders
|
|
173
259
|
for(let key in current_env) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
260
|
+
let val = current_env[key]
|
|
261
|
+
let is_absolute = path.isAbsolute(val)
|
|
262
|
+
let is_relative = val.startsWith("./")
|
|
263
|
+
if (is_absolute || is_relative) {
|
|
264
|
+
// it's a path
|
|
265
|
+
let full_path = path.resolve(homedir, val)
|
|
178
266
|
await fs.promises.mkdir(full_path, { recursive: true }).catch((e) => {})
|
|
179
267
|
}
|
|
180
268
|
}
|
|
181
269
|
}
|
|
270
|
+
|
|
271
|
+
// Get the actual environment variable at specific path
|
|
272
|
+
const get2 = async (filepath, kernel) => {
|
|
273
|
+
let api_path = Util.api_path(filepath, kernel)
|
|
274
|
+
let default_env = await get(kernel.homedir)
|
|
275
|
+
let api_env = await get(api_path)
|
|
276
|
+
let current_env = Object.assign(process.env, default_env, api_env)
|
|
277
|
+
return current_env
|
|
278
|
+
}
|
|
182
279
|
const get = async (homedir) => {
|
|
183
280
|
const env_path = path.resolve(homedir, "ENVIRONMENT")
|
|
184
|
-
const current_env = await
|
|
185
|
-
// if the key is a folder/cache_folder type, resolve the path
|
|
281
|
+
const current_env = await Util.parse_env(env_path)
|
|
186
282
|
for(let key in current_env) {
|
|
187
|
-
|
|
188
|
-
|
|
283
|
+
let val = current_env[key]
|
|
284
|
+
if (val.startsWith("./")) {
|
|
285
|
+
let full_path = path.resolve(homedir, val)
|
|
189
286
|
current_env[key] = full_path
|
|
190
287
|
}
|
|
288
|
+
if (val.trim() === "") {
|
|
289
|
+
delete current_env[key]
|
|
290
|
+
}
|
|
191
291
|
}
|
|
192
292
|
return current_env
|
|
193
293
|
}
|
|
194
|
-
module.exports = { ENV, get,
|
|
294
|
+
module.exports = { ENV, get, get2, init_folders }
|
package/kernel/index.js
CHANGED
|
@@ -33,7 +33,7 @@ const VARS = {
|
|
|
33
33
|
//const memwatch = require('@airbnb/node-memwatch');
|
|
34
34
|
class Kernel {
|
|
35
35
|
//schema = ">=1.0.0"
|
|
36
|
-
schema = "<=
|
|
36
|
+
schema = "<=2.0.0"
|
|
37
37
|
constructor(store) {
|
|
38
38
|
this.fetch = fetch
|
|
39
39
|
this.store = store
|
|
@@ -57,11 +57,9 @@ class Kernel {
|
|
|
57
57
|
} else {
|
|
58
58
|
folderpath = this.homedir
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
let api_path = await Util.api_path(folderpath, this)
|
|
60
|
+
let api_path = Util.api_path(folderpath, this)
|
|
62
61
|
let current_env = await Environment.get(api_path)
|
|
63
62
|
let default_env = await Environment.get(this.homedir)
|
|
64
|
-
console.log({ api_path, current_env, default_env })
|
|
65
63
|
return Object.assign(process.env, default_env, current_env)
|
|
66
64
|
}
|
|
67
65
|
resumeprocess(uri) {
|
|
@@ -269,7 +267,7 @@ class Kernel {
|
|
|
269
267
|
// if it doesn't exist, write to ~/pinokio/ENVIRONMENT
|
|
270
268
|
let e = await this.exists(this.homedir, "ENVIRONMENT")
|
|
271
269
|
if (!e) {
|
|
272
|
-
let str = Environment.ENV(
|
|
270
|
+
let str = Environment.ENV("system")
|
|
273
271
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
274
272
|
}
|
|
275
273
|
// 2. mkdir all the folders if not already created
|
package/kernel/shell.js
CHANGED
|
@@ -71,8 +71,6 @@ class Shell {
|
|
|
71
71
|
this.cols = params.cols ? params.cols : 100;
|
|
72
72
|
this.rows = params.rows ? params.rows : 30;
|
|
73
73
|
|
|
74
|
-
console.log({ cols: this.cols, rows: this.rows })
|
|
75
|
-
|
|
76
74
|
this.vt = new Terminal({
|
|
77
75
|
allowProposedApi: true,
|
|
78
76
|
cols: this.cols,
|
|
@@ -121,7 +119,7 @@ class Shell {
|
|
|
121
119
|
// if the shell is running from a script file, the params.$parent will include the path to the parent script
|
|
122
120
|
// this means we need to apply app environment as well
|
|
123
121
|
if (params.$parent) {
|
|
124
|
-
let api_path =
|
|
122
|
+
let api_path = Util.api_path(params.$parent.path, this.kernel)
|
|
125
123
|
|
|
126
124
|
// initialize folders
|
|
127
125
|
await Environment.init_folders(api_path)
|
package/kernel/util.js
CHANGED
|
@@ -67,7 +67,7 @@ const parse_env_detail = async (filename) => {
|
|
|
67
67
|
*/
|
|
68
68
|
return items
|
|
69
69
|
}
|
|
70
|
-
const api_path =
|
|
70
|
+
const api_path = (fullpath, kernel) => {
|
|
71
71
|
let api_path = `${kernel.homedir}${path.sep}api`
|
|
72
72
|
let rel_path = path.relative(api_path, fullpath)
|
|
73
73
|
let api_name = rel_path.split(path.sep)[0]
|
|
@@ -87,40 +87,37 @@ const escapeStringRegexp = (string) => {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
const update_env = async (filepath, changes) => {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
let hasAppended = false;
|
|
93
|
-
console.log("changes", changes)
|
|
90
|
+
const env = await fs.promises.readFile(filepath, "utf8")
|
|
91
|
+
let append = false;
|
|
94
92
|
const newval = Object.keys(changes).reduce((result, varname) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
console.log("updated ENVIRONMENT", newval)
|
|
93
|
+
const value = changes[varname].toString()
|
|
94
|
+
.replace(breakPattern, breakReplacement)
|
|
95
|
+
.replace(returnPattern, returnReplacement)
|
|
96
|
+
.trim();
|
|
97
|
+
const safeName = escapeStringRegexp(varname);
|
|
98
|
+
const varPattern = new RegExp(`^(${h}*${safeName}${h}*=${h}*)\\S*(${h}*)$`, "gm");
|
|
99
|
+
if (varPattern.test(result)) {
|
|
100
|
+
const safeValue = value.replace(groupPattern, groupReplacement);
|
|
101
|
+
return result.replace(varPattern, `$1${safeValue}$2`);
|
|
102
|
+
} else if (result === "") {
|
|
103
|
+
append = true;
|
|
104
|
+
return `${varname}=${value}${EOL}`;
|
|
105
|
+
} else if (!result.endsWith(EOL) && !append) {
|
|
106
|
+
append = true;
|
|
107
|
+
// Add an extra break between previously defined and newly appended variable
|
|
108
|
+
return `${result}${EOL}${EOL}${varname}=${value}`;
|
|
109
|
+
} else if (!result.endsWith(EOL)) {
|
|
110
|
+
// Add break for appended variable
|
|
111
|
+
return `${result}${EOL}${varname}=${value}`;
|
|
112
|
+
} else if (result.endsWith(EOL) && !append) {
|
|
113
|
+
append = true;
|
|
114
|
+
// Add an extra break between previously defined and newly appended variable
|
|
115
|
+
return `${result}${EOL}${varname}=${value}${EOL}`;
|
|
116
|
+
} else {
|
|
117
|
+
// Add break for appended variable
|
|
118
|
+
return `${result}${varname}=${value}${EOL}`;
|
|
119
|
+
}
|
|
120
|
+
}, normalizeEOL(env));
|
|
124
121
|
await fs.promises.writeFile(filepath, newval)
|
|
125
122
|
};
|
|
126
123
|
module.exports = {
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -229,26 +229,21 @@ class Server {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
console.log("M", mem)
|
|
233
232
|
|
|
234
233
|
let current = this.kernel.path("api", name, "ENVIRONMENT")
|
|
235
234
|
// if environment.json doesn't exist,
|
|
236
235
|
let exists = await this.exists(current)
|
|
237
|
-
console.log("exists", exists)
|
|
238
236
|
if (!exists) {
|
|
239
|
-
let content = await Environment.
|
|
240
|
-
console.log("write", content)
|
|
237
|
+
let content = await Environment.ENV("app")
|
|
241
238
|
await fs.promises.writeFile(current, content)
|
|
242
239
|
}
|
|
243
240
|
|
|
244
241
|
let mode = "run"
|
|
245
|
-
console.log("req.query", req.query)
|
|
246
242
|
if (req.query && req.query.mode) {
|
|
247
243
|
mode = req.query.mode
|
|
248
244
|
}
|
|
249
245
|
|
|
250
246
|
const env = await this.kernel.env("api/" + name)
|
|
251
|
-
console.log("env", env)
|
|
252
247
|
|
|
253
248
|
//res.render("browser", {
|
|
254
249
|
res.render("browser-experimental", {
|
|
@@ -378,7 +373,7 @@ class Server {
|
|
|
378
373
|
// if environment.json doesn't exist,
|
|
379
374
|
let exists = await this.exists(filepath)
|
|
380
375
|
if (!exists) {
|
|
381
|
-
let content = await Environment.
|
|
376
|
+
let content = await Environment.ENV("app")
|
|
382
377
|
await fs.promises.writeFile(filepath, content)
|
|
383
378
|
}
|
|
384
379
|
}
|
|
@@ -902,7 +897,6 @@ class Server {
|
|
|
902
897
|
execUrl: "~" + req.originalUrl.replace(/^\/_api/, "\/api"),
|
|
903
898
|
proxies: this.kernel.api.proxies[filepath],
|
|
904
899
|
}
|
|
905
|
-
console.log("result", result)
|
|
906
900
|
|
|
907
901
|
res.render(template, result)
|
|
908
902
|
} else {
|
|
@@ -1114,7 +1108,6 @@ class Server {
|
|
|
1114
1108
|
|
|
1115
1109
|
// check if there is a running process with this folder name
|
|
1116
1110
|
let runningApps = new Set()
|
|
1117
|
-
console.log("running", this.kernel.api.running)
|
|
1118
1111
|
for(let key in this.kernel.api.running) {
|
|
1119
1112
|
let p = this.kernel.path("api", items[i].name) + path.sep
|
|
1120
1113
|
//let re = new RegExp(items[i].name)
|
|
@@ -1172,11 +1165,6 @@ class Server {
|
|
|
1172
1165
|
qr_cloudflare = await QRCode.toDataURL(this.cloudflare_pub)
|
|
1173
1166
|
}
|
|
1174
1167
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
console.log("running", JSON.stringify(running, null, 2))
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
1168
|
res.render("index", {
|
|
1181
1169
|
home_url: `http://localhost:${this.port}`,
|
|
1182
1170
|
proxy: home_proxy,
|
|
@@ -1284,25 +1272,25 @@ class Server {
|
|
|
1284
1272
|
async renderMenu(uri, name, config, pathComponents) {
|
|
1285
1273
|
if (config.menu) {
|
|
1286
1274
|
|
|
1287
|
-
config.menu = [{
|
|
1288
|
-
base: "/",
|
|
1289
|
-
text: "Configure",
|
|
1290
|
-
href: `env/api/${name}/ENVIRONMENT`,
|
|
1291
|
-
icon: "fa-solid fa-gear"
|
|
1292
|
-
mode: "refresh"
|
|
1293
|
-
// }, {
|
|
1275
|
+
// config.menu = [{
|
|
1294
1276
|
// base: "/",
|
|
1295
|
-
// text: "
|
|
1296
|
-
// action: {
|
|
1297
|
-
// method: "env.set",
|
|
1298
|
-
// params: {
|
|
1299
|
-
// "PINOKIO_SHARE_CLOUDFLARE": true,
|
|
1300
|
-
// "PINOKIO_SHARE_LOCAL": true
|
|
1301
|
-
// }
|
|
1302
|
-
// },
|
|
1277
|
+
// text: "Configure",
|
|
1303
1278
|
// href: `env/api/${name}/ENVIRONMENT`,
|
|
1304
|
-
// icon: "fa-solid fa-gear"
|
|
1305
|
-
|
|
1279
|
+
// icon: "fa-solid fa-gear",
|
|
1280
|
+
// mode: "refresh"
|
|
1281
|
+
//// }, {
|
|
1282
|
+
//// base: "/",
|
|
1283
|
+
//// text: "Public Share",
|
|
1284
|
+
//// action: {
|
|
1285
|
+
//// method: "env.set",
|
|
1286
|
+
//// params: {
|
|
1287
|
+
//// "PINOKIO_SHARE_CLOUDFLARE": true,
|
|
1288
|
+
//// "PINOKIO_SHARE_LOCAL": true
|
|
1289
|
+
//// }
|
|
1290
|
+
//// },
|
|
1291
|
+
//// href: `env/api/${name}/ENVIRONMENT`,
|
|
1292
|
+
//// icon: "fa-solid fa-gear"
|
|
1293
|
+
// }].concat(config.menu)
|
|
1306
1294
|
|
|
1307
1295
|
for(let i=0; i<config.menu.length; i++) {
|
|
1308
1296
|
let menuitem = config.menu[i]
|
|
@@ -1464,7 +1452,6 @@ class Server {
|
|
|
1464
1452
|
|
|
1465
1453
|
|
|
1466
1454
|
|
|
1467
|
-
console.log("MENU", config.menu)
|
|
1468
1455
|
|
|
1469
1456
|
|
|
1470
1457
|
|
|
@@ -1899,7 +1886,7 @@ class Server {
|
|
|
1899
1886
|
if (this.kernel.homedir) {
|
|
1900
1887
|
let ex = await this.kernel.exists(this.kernel.homedir, "ENVIRONMENT")
|
|
1901
1888
|
if (!ex) {
|
|
1902
|
-
let str = Environment.ENV(
|
|
1889
|
+
let str = Environment.ENV("system")
|
|
1903
1890
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
1904
1891
|
}
|
|
1905
1892
|
|
package/server/socket.js
CHANGED
|
@@ -115,7 +115,6 @@ class Socket {
|
|
|
115
115
|
raw: res.data.raw
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
console.log("*** res1", res)
|
|
119
118
|
subscriber.send(JSON.stringify(res))
|
|
120
119
|
}
|
|
121
120
|
});
|
|
@@ -144,7 +143,6 @@ class Socket {
|
|
|
144
143
|
raw: res.data.raw
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
|
-
console.log("*** res2", res)
|
|
148
146
|
subscriber.send(JSON.stringify(res))
|
|
149
147
|
|
|
150
148
|
}
|
|
@@ -554,6 +554,9 @@ body.dark .loader-container {
|
|
|
554
554
|
<a target="/share/<%=name%>" href="/share/<%=name%>", class="btn header-item frame-link" data-index="1" data-mode="refresh">
|
|
555
555
|
<div class='tab'><i class="fa-solid fa-wifi"></i> Share</div>
|
|
556
556
|
</a>
|
|
557
|
+
<a target="/env/api/<%=name%>/ENVIRONMENT" href="/env/api/<%=name%>/ENVIRONMENT", class="btn header-item frame-link" data-index="1" data-mode="refresh">
|
|
558
|
+
<div class='tab'><i class="fa-solid fa-gear"></i> Configure</div>
|
|
559
|
+
</a>
|
|
557
560
|
</div>
|
|
558
561
|
<div class='m h menu' data-type='h'>
|
|
559
562
|
<% if (config.menu) { %>
|
package/server/views/explore.ejs
CHANGED
|
@@ -147,9 +147,9 @@ body main iframe {
|
|
|
147
147
|
</header>
|
|
148
148
|
<main>
|
|
149
149
|
<% if (theme === "dark") { %>
|
|
150
|
-
<iframe name="<%=schema%>" src="https://pinokio.computer/dark" no-referrer
|
|
150
|
+
<iframe name="<%=schema%>" src="https://pinokio.computer/dark" <%=agent === "electron" ? "no-referrer" : ""%>></iframe>
|
|
151
151
|
<% } else { %>
|
|
152
|
-
<iframe name="<%=schema%>" src="https://pinokio.computer/app" no-referrer
|
|
152
|
+
<iframe name="<%=schema%>" src="https://pinokio.computer/app" <%=agent === "electron" ? "no-referrer" : ""%>></iframe>
|
|
153
153
|
<% } %>
|
|
154
154
|
</main>
|
|
155
155
|
<link href="/xterm.min.css" rel="stylesheet" />
|
|
@@ -190,7 +190,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
190
190
|
return new Promise(async (resolve, reject) => {
|
|
191
191
|
// await this.save()
|
|
192
192
|
await this.socket.close()
|
|
193
|
-
console.log({ cols: this.term.cols, rows: this.term.rows })
|
|
194
193
|
|
|
195
194
|
let query = Object.fromEntries(new URLSearchParams(location.search))
|
|
196
195
|
|
|
@@ -205,11 +204,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
205
204
|
rows: this.term.rows,
|
|
206
205
|
}
|
|
207
206
|
}, async (packet) => {
|
|
208
|
-
|
|
209
|
-
console.log("packet", packet.type, packet)
|
|
210
|
-
if (packet.data) {
|
|
211
|
-
console.log("packet.data.raw", packet.data.raw)
|
|
212
|
-
}
|
|
213
207
|
if (packet.type === 'start') {
|
|
214
208
|
refreshParent(packet)
|
|
215
209
|
reloadMemory()
|
|
@@ -241,7 +235,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
241
235
|
// </div>`
|
|
242
236
|
}
|
|
243
237
|
} else if (packet.type === "stream") {
|
|
244
|
-
console.log({ cols: this.term.cols, rows: this.term.rows })
|
|
245
238
|
if (packet.data.raw) {
|
|
246
239
|
this.write(packet.data.raw)
|
|
247
240
|
} else if (packet.data.json) {
|
|
@@ -257,7 +250,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
257
250
|
} else if (packet.type === 'disconnect') {
|
|
258
251
|
refreshParent(packet)
|
|
259
252
|
reloadMemory()
|
|
260
|
-
|
|
253
|
+
this.term.write("\r\nDisconnected...\r\n")
|
|
261
254
|
document.querySelector("footer").innerHTML = "<b>Ready</b>"
|
|
262
255
|
this.socket.close()
|
|
263
256
|
document.querySelector(".run .play").classList.remove("hidden")
|