pinokiod 2.1.2 → 2.1.4
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/index.js +7 -0
- package/kernel/api/local/index.js +9 -1
- package/kernel/api/proxy/index.js +1 -0
- package/kernel/environment.js +265 -238
- package/kernel/index.js +22 -17
- package/package.json +3 -3
- package/script/index.js +0 -2
- package/server/index.js +38 -6
- package/server/views/download.ejs +1 -1
- package/server/views/share_editor.ejs +13 -0
package/kernel/api/index.js
CHANGED
|
@@ -38,6 +38,7 @@ class Api {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
async startProxy(scriptPath, uri, name, options) {
|
|
41
|
+
console.log("startProxy", { scriptPath, uri, name, options })
|
|
41
42
|
this.checkProxy({ uri, name })
|
|
42
43
|
// if the name exists, throw error
|
|
43
44
|
// if the uri exists, throw error
|
|
@@ -57,10 +58,13 @@ class Api {
|
|
|
57
58
|
// stop all proxies for the script
|
|
58
59
|
if (this.proxies[config.script]) {
|
|
59
60
|
for(let p of this.proxies[config.script]) {
|
|
61
|
+
console.log("stopProxy", p.target)
|
|
60
62
|
this.stopProxy({ uri: p.target })
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
} else if (config.uri) {
|
|
66
|
+
console.log("stopProxy uri", config)
|
|
67
|
+
console.log("this.proxies = ", this.proxies)
|
|
64
68
|
|
|
65
69
|
// stop the proxy
|
|
66
70
|
this.lproxy.stop(config.uri)
|
|
@@ -105,6 +109,7 @@ class Api {
|
|
|
105
109
|
// 2. stream a message closing the socket
|
|
106
110
|
|
|
107
111
|
|
|
112
|
+
console.log("stop params", req.params)
|
|
108
113
|
|
|
109
114
|
let requestPath = this.filePath(req.params.uri)
|
|
110
115
|
|
|
@@ -348,6 +353,7 @@ class Api {
|
|
|
348
353
|
return modpath
|
|
349
354
|
}
|
|
350
355
|
filePath(uri, cwd) {
|
|
356
|
+
console.log({ uri, cwd })
|
|
351
357
|
let modpath
|
|
352
358
|
if (uri.startsWith("http")) {
|
|
353
359
|
// git url
|
|
@@ -1109,6 +1115,7 @@ class Api {
|
|
|
1109
1115
|
rawrpc: request
|
|
1110
1116
|
})
|
|
1111
1117
|
} catch (e) {
|
|
1118
|
+
console.log("ERROR", e)
|
|
1112
1119
|
this.ondata({
|
|
1113
1120
|
kernel: true,
|
|
1114
1121
|
id: request.method,
|
|
@@ -84,9 +84,17 @@ class Local {
|
|
|
84
84
|
if ("PINOKIO_SHARE_LOCAL" in current_env) {
|
|
85
85
|
let val = current_env.PINOKIO_SHARE_LOCAL.trim().toLowerCase()
|
|
86
86
|
if (val === "true" || val === "1") {
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
req.params.name = "Local Sharing",
|
|
89
89
|
req.params.uri = req.params[KEY]
|
|
90
|
+
if ("PINOKIO_SHARE_LOCAL_PORT" in current_env) {
|
|
91
|
+
let port = current_env.PINOKIO_SHARE_LOCAL_PORT.trim().toLowerCase()
|
|
92
|
+
if (port.length > 0) {
|
|
93
|
+
console.log("start proxy at custom port", port)
|
|
94
|
+
req.params.port = port
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const p = new Proxy()
|
|
90
98
|
await p.start(req, ondata, kernel)
|
|
91
99
|
}
|
|
92
100
|
}
|
package/kernel/environment.js
CHANGED
|
@@ -1,244 +1,270 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
|
+
const portfinder = require('portfinder-cp')
|
|
2
3
|
const os = require('os')
|
|
3
4
|
const fs = require('fs')
|
|
4
5
|
const Util = require('./util')
|
|
5
6
|
const platform = os.platform()
|
|
6
|
-
const ENVS =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
"
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"
|
|
224
|
-
|
|
225
|
-
"
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
7
|
+
const ENVS = async () => {
|
|
8
|
+
const primary_port = 80
|
|
9
|
+
const secondary_port = 42000
|
|
10
|
+
const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
|
|
11
|
+
let port
|
|
12
|
+
if (available) {
|
|
13
|
+
port = primary_port
|
|
14
|
+
} else {
|
|
15
|
+
port = secondary_port
|
|
16
|
+
}
|
|
17
|
+
return [{
|
|
18
|
+
type: ["system"],
|
|
19
|
+
key: "HOMEBREW_CACHE",
|
|
20
|
+
hidden: true,
|
|
21
|
+
val: "./cache/HOMEBREW_CACHE"
|
|
22
|
+
}, {
|
|
23
|
+
type: ["system"],
|
|
24
|
+
key: "XDG_CACHE_HOME",
|
|
25
|
+
hidden: true,
|
|
26
|
+
val: "./cache/XDG_CACHE_HOME"
|
|
27
|
+
}, {
|
|
28
|
+
type: ["system"],
|
|
29
|
+
key: "PIP_CACHE_DIR",
|
|
30
|
+
hidden: true,
|
|
31
|
+
val: "./cache/PIP_CACHE_DIR"
|
|
32
|
+
}, {
|
|
33
|
+
type: ["system"],
|
|
34
|
+
key: "PIP_TMPDIR",
|
|
35
|
+
hidden: true,
|
|
36
|
+
val: "./cache/PIP_TMPDIR"
|
|
37
|
+
}, {
|
|
38
|
+
type: ["system"],
|
|
39
|
+
key: "TMPDIR",
|
|
40
|
+
hidden: true,
|
|
41
|
+
val: "./cache/TMPDIR"
|
|
42
|
+
}, {
|
|
43
|
+
type: ["system"],
|
|
44
|
+
key: "TEMP",
|
|
45
|
+
hidden: true,
|
|
46
|
+
val: "./cache/TEMP"
|
|
47
|
+
}, {
|
|
48
|
+
type: ["system"],
|
|
49
|
+
key: "TMP",
|
|
50
|
+
hidden: true,
|
|
51
|
+
val: "./cache/TMP"
|
|
52
|
+
}, {
|
|
53
|
+
type: ["system"],
|
|
54
|
+
key: "XDG_DATA_HOME",
|
|
55
|
+
hidden: true,
|
|
56
|
+
val: "./cache/XDG_DATA_HOME"
|
|
57
|
+
}, {
|
|
58
|
+
type: ["system"],
|
|
59
|
+
key: "XDG_CONFIG_HOME",
|
|
60
|
+
hidden: true,
|
|
61
|
+
val: "./cache/XDG_CONFIG_HOME"
|
|
62
|
+
}, {
|
|
63
|
+
type: ["system"],
|
|
64
|
+
key: "XDG_STATE_HOME",
|
|
65
|
+
hidden: true,
|
|
66
|
+
val: "./cache/XDG_STATE_HOME"
|
|
67
|
+
}, {
|
|
68
|
+
type: ["system"],
|
|
69
|
+
key: "PIP_CONFIG_FILE",
|
|
70
|
+
hidden: true,
|
|
71
|
+
val: "./pipconfig"
|
|
72
|
+
}, {
|
|
73
|
+
type: ["system"],
|
|
74
|
+
key: "CONDARC",
|
|
75
|
+
hidden: true,
|
|
76
|
+
val: "./condarc"
|
|
77
|
+
}, {
|
|
78
|
+
type: ["system"],
|
|
79
|
+
key: "PS1",
|
|
80
|
+
hidden: true,
|
|
81
|
+
val: "<<PINOKIO SHELL>> "
|
|
82
|
+
}, {
|
|
83
|
+
type: ["system"],
|
|
84
|
+
key: "GRADIO_ANALYTICS_ENABLED",
|
|
85
|
+
val: "False"
|
|
86
|
+
}, {
|
|
87
|
+
type: ["system"],
|
|
88
|
+
key: "GRADIO_ALLOWED_PATHS",
|
|
89
|
+
val: "./",
|
|
90
|
+
comment: [
|
|
91
|
+
"##########################################################################",
|
|
92
|
+
"#",
|
|
93
|
+
"# GRADIO_ALLOWED_PATHS",
|
|
94
|
+
"#",
|
|
95
|
+
"# This allows every Gradio app installed under Pinokio to serve files",
|
|
96
|
+
"# outside of each app's root folder, which is useful for many cases.",
|
|
97
|
+
"# Do not touch this unless you want to add additional paths",
|
|
98
|
+
"#",
|
|
99
|
+
"##########################################################################",
|
|
100
|
+
],
|
|
101
|
+
}, {
|
|
102
|
+
type: ["system"],
|
|
103
|
+
key: "PINOKIO_SHARE_VAR",
|
|
104
|
+
val: "url",
|
|
105
|
+
comment: [
|
|
106
|
+
"##########################################################################",
|
|
107
|
+
"#",
|
|
108
|
+
"# PINOKIO_SHARE_VAR",
|
|
109
|
+
"#",
|
|
110
|
+
"# When you set this local variable from any script, it will trigger Pinokio",
|
|
111
|
+
"# share actions (local sharing, cloudflare, ...)",
|
|
112
|
+
"#",
|
|
113
|
+
"# You can customize whether to avoid this using PINOKIO_SHARE_CLOUDFLARE",
|
|
114
|
+
"# and PINOKIO_SHARE_LOCAL",
|
|
115
|
+
"#",
|
|
116
|
+
"##########################################################################",
|
|
117
|
+
],
|
|
118
|
+
}, {
|
|
119
|
+
type: ["system", "app"],
|
|
120
|
+
key: "PINOKIO_SHARE_CLOUDFLARE",
|
|
121
|
+
val: "false",
|
|
122
|
+
comment: [
|
|
123
|
+
"##########################################################################",
|
|
124
|
+
"#",
|
|
125
|
+
"# PINOKIO_SHARE_CLOUDFLARE",
|
|
126
|
+
"# Set this variable to share the app publicly via cloudflare tunnel.",
|
|
127
|
+
"#",
|
|
128
|
+
"##########################################################################",
|
|
129
|
+
]
|
|
130
|
+
}, {
|
|
131
|
+
type: ["app"],
|
|
132
|
+
key: "PINOKIO_SHARE_PASSCODE",
|
|
133
|
+
val: "",
|
|
134
|
+
comment: [
|
|
135
|
+
"##########################################################################",
|
|
136
|
+
"#",
|
|
137
|
+
"# PINOKIO_SHARE_PASSCODE",
|
|
138
|
+
"#",
|
|
139
|
+
"# By default, your publicly shared app will be 100% open to anyone",
|
|
140
|
+
"# with the link via Cloudflare.",
|
|
141
|
+
"#",
|
|
142
|
+
"# You can add authorization by protecting it with a passcode.",
|
|
143
|
+
"# Set this value, and any access to the app will require a pass code input",
|
|
144
|
+
"#",
|
|
145
|
+
"##########################################################################",
|
|
146
|
+
],
|
|
147
|
+
}, {
|
|
148
|
+
type: ["system", "app"],
|
|
149
|
+
key: "PINOKIO_SCRIPT_DEFAULT",
|
|
150
|
+
val: "true",
|
|
151
|
+
comment: [
|
|
152
|
+
"##########################################################################",
|
|
153
|
+
"#",
|
|
154
|
+
"# PINOKIO_SCRIPT_DEFAULT",
|
|
155
|
+
"# If this variable is false, 'default': true menu items in pinokio.js",
|
|
156
|
+
"# will NOT automatically run",
|
|
157
|
+
"#",
|
|
158
|
+
"##########################################################################",
|
|
159
|
+
]
|
|
160
|
+
}, {
|
|
161
|
+
type: ["system"],
|
|
162
|
+
key: "PINOKIO_DRIVE",
|
|
163
|
+
val: "./drive",
|
|
164
|
+
comment: [
|
|
165
|
+
"##########################################################################",
|
|
166
|
+
"#",
|
|
167
|
+
"# PINOKIO_DRIVE",
|
|
168
|
+
"#",
|
|
169
|
+
"# The virtual drive path.",
|
|
170
|
+
"# Change it if you want to use a different path.",
|
|
171
|
+
"# You can even enter an absolute path to use a folder outside of pinokio",
|
|
172
|
+
"# or an entirely different disk drive",
|
|
173
|
+
"#",
|
|
174
|
+
"##########################################################################",
|
|
175
|
+
],
|
|
176
|
+
}, {
|
|
177
|
+
type: ["system"],
|
|
178
|
+
key: "PINOKIO_PORT",
|
|
179
|
+
val: `${port}`,
|
|
180
|
+
comment: [
|
|
181
|
+
"##########################################################################",
|
|
182
|
+
"#",
|
|
183
|
+
"# PINOKIO_PORT",
|
|
184
|
+
"#",
|
|
185
|
+
"# The server port Pinokio will use. By default it's 80 but you can",
|
|
186
|
+
"# Change it to anything else",
|
|
187
|
+
"#",
|
|
188
|
+
"##########################################################################",
|
|
189
|
+
],
|
|
190
|
+
}, {
|
|
191
|
+
type: ["system", "app"],
|
|
192
|
+
key: "GRADIO_TEMP_DIR",
|
|
193
|
+
val: "./cache/GRADIO_TEMP_DIR",
|
|
194
|
+
comment: [
|
|
195
|
+
"##########################################################################",
|
|
196
|
+
"#",
|
|
197
|
+
"# GRADIO_TEMP_DIR",
|
|
198
|
+
"# All the files uploaded through gradio goes here.",
|
|
199
|
+
"#",
|
|
200
|
+
"# Delete this line to store the files under PINOKIO_HOME/cache/GRADIO_TEMPDIR",
|
|
201
|
+
"# or change the path if you want to use a different path",
|
|
202
|
+
"#",
|
|
203
|
+
"##########################################################################",
|
|
204
|
+
],
|
|
205
|
+
}, {
|
|
206
|
+
type: ["system", "app"],
|
|
207
|
+
key: "HF_HOME",
|
|
208
|
+
val: "./cache/HF_HOME",
|
|
209
|
+
comment: [
|
|
210
|
+
"##########################################################################",
|
|
211
|
+
"#",
|
|
212
|
+
"# HF_HOME",
|
|
213
|
+
"#",
|
|
214
|
+
"# Huggingface cache",
|
|
215
|
+
"# All the model files automatically downloaded through libraries like",
|
|
216
|
+
"# diffusers, transformers, etc. will be stored under this path",
|
|
217
|
+
"#",
|
|
218
|
+
"# You can save disk space by deleting this line, which will store all",
|
|
219
|
+
"# huggingface files under PINOKIO_HOME/cache/HF_HOME without redundancy.",
|
|
220
|
+
"#",
|
|
221
|
+
"##########################################################################",
|
|
222
|
+
],
|
|
223
|
+
}, {
|
|
224
|
+
type: ["system", "app"],
|
|
225
|
+
key: "TORCH_HOME",
|
|
226
|
+
val: "./cache/TORCH_HOME",
|
|
227
|
+
comment: [
|
|
228
|
+
"##########################################################################",
|
|
229
|
+
"#",
|
|
230
|
+
"# TORCH_HOME",
|
|
231
|
+
"#",
|
|
232
|
+
"# Torch hub cache",
|
|
233
|
+
"# All the files automatically downloaded by pytorch will be stored here",
|
|
234
|
+
"#",
|
|
235
|
+
"# You can save disk space by deleting this line, which will store all",
|
|
236
|
+
"# torch hub files under PINOKIO_HOME/cache/TORCH_HOME without redundancy.",
|
|
237
|
+
"#",
|
|
238
|
+
"##########################################################################",
|
|
239
|
+
],
|
|
240
|
+
}, {
|
|
241
|
+
type: ["system", "app"],
|
|
242
|
+
key: "PINOKIO_SHARE_LOCAL",
|
|
243
|
+
val: "false",
|
|
244
|
+
comment: [
|
|
245
|
+
"##########################################################################",
|
|
246
|
+
"#",
|
|
247
|
+
"# PINOKIO_SHARE_LOCAL",
|
|
248
|
+
"# Set this variable to true to share the app on the local network.",
|
|
249
|
+
"#",
|
|
250
|
+
"##########################################################################",
|
|
251
|
+
],
|
|
252
|
+
}, {
|
|
253
|
+
type: ["system", "app"],
|
|
254
|
+
key: "PINOKIO_SHARE_LOCAL_PORT",
|
|
255
|
+
val: "",
|
|
256
|
+
comment: [
|
|
257
|
+
"##########################################################################",
|
|
258
|
+
"#",
|
|
259
|
+
"# PINOKIO_SHARE_LOCAL_PORT",
|
|
260
|
+
"# Set this variable to use fixed port for the local network sharing feature",
|
|
261
|
+
"# If not specified, a random port will be assigned to the local proxy used",
|
|
262
|
+
"# for local sharing.",
|
|
263
|
+
"#",
|
|
264
|
+
"##########################################################################",
|
|
265
|
+
],
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
242
268
|
//const ENV = (homedir) => {
|
|
243
269
|
// const lines = ENVS.map((e) => {
|
|
244
270
|
// if (e.type) {
|
|
@@ -255,8 +281,9 @@ const ENVS = [{
|
|
|
255
281
|
//}
|
|
256
282
|
|
|
257
283
|
// type := system|app
|
|
258
|
-
const ENV = (type) => {
|
|
259
|
-
|
|
284
|
+
const ENV = async (type) => {
|
|
285
|
+
const envs = await ENVS()
|
|
286
|
+
return envs.filter((e) => {
|
|
260
287
|
return e.type.includes(type)
|
|
261
288
|
}).map((e) => {
|
|
262
289
|
let comment = ""
|
package/kernel/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const fetch = require('cross-fetch');
|
|
|
8
8
|
const waitOn = require('wait-on');
|
|
9
9
|
const system = require('systeminformation');
|
|
10
10
|
const Sysinfo = require('./sysinfo')
|
|
11
|
-
const portfinder = require('portfinder');
|
|
11
|
+
const portfinder = require('portfinder-cp');
|
|
12
12
|
const Loader = require("./loader")
|
|
13
13
|
const Bin = require('./bin')
|
|
14
14
|
const Api = require("./api")
|
|
@@ -60,16 +60,18 @@ class Kernel {
|
|
|
60
60
|
let scriptPath = option.path
|
|
61
61
|
if (this.memory.local[scriptPath] && this.memory.local[scriptPath].$share) {
|
|
62
62
|
let cf = this.memory.local[scriptPath].$share.cloudflare
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
if (cf) {
|
|
64
|
+
let uris = Object.keys(cf)
|
|
65
|
+
for(let uri of uris) {
|
|
66
|
+
await this.cloudflare.stop({
|
|
67
|
+
parent: {
|
|
68
|
+
path: scriptPath
|
|
69
|
+
},
|
|
70
|
+
params: { uri }
|
|
71
|
+
}, (e) => {
|
|
72
|
+
process.stdout.write(e.raw)
|
|
73
|
+
}, this)
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -132,16 +134,19 @@ class Kernel {
|
|
|
132
134
|
let id = this.api.filePath(uri, cwd)
|
|
133
135
|
return this.api.running[id]
|
|
134
136
|
}
|
|
135
|
-
port() {
|
|
137
|
+
port(port) {
|
|
138
|
+
// 1. if port is passed, check port
|
|
139
|
+
// 2. if no port is passed, get the next available port
|
|
136
140
|
/**********************************************
|
|
137
141
|
*
|
|
138
142
|
* let available_port = await kernel.port()
|
|
139
143
|
*
|
|
140
144
|
**********************************************/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
+
if (port) {
|
|
146
|
+
return portfinder.isAvailablePromise({ host: "0.0.0.0", port })
|
|
147
|
+
} else {
|
|
148
|
+
return portfinder.getPortPromise({ port: 42000 })
|
|
149
|
+
}
|
|
145
150
|
}
|
|
146
151
|
path(...args) {
|
|
147
152
|
return path.resolve(this.homedir, ...args)
|
|
@@ -291,7 +296,7 @@ class Kernel {
|
|
|
291
296
|
// if it doesn't exist, write to ~/pinokio/ENVIRONMENT
|
|
292
297
|
let e = await this.exists(this.homedir, "ENVIRONMENT")
|
|
293
298
|
if (!e) {
|
|
294
|
-
let str = Environment.ENV("system")
|
|
299
|
+
let str = await Environment.ENV("system")
|
|
295
300
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
296
301
|
}
|
|
297
302
|
// 2. mkdir all the folders if not already created
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinokiod",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"key-store": "^1.2.0",
|
|
40
40
|
"kleur": "^4.1.5",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
|
-
"lproxy": "^0.0.
|
|
42
|
+
"lproxy": "^0.0.12",
|
|
43
43
|
"marked": "^5.0.1",
|
|
44
44
|
"mime-types": "^2.1.35",
|
|
45
45
|
"multer": "^1.4.5-lts.1",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"node-gradio-client": "^0.14.6",
|
|
48
48
|
"node-pty-prebuilt-multiarch-cp": "^0.10.1-pre.48",
|
|
49
49
|
"pdrive": "^0.0.25",
|
|
50
|
-
"portfinder": "^1.0.
|
|
50
|
+
"portfinder-cp": "^1.0.34",
|
|
51
51
|
"qrcode": "^1.5.3",
|
|
52
52
|
"random-useragent": "^0.5.0",
|
|
53
53
|
"rimraf": "^5.0.0",
|
package/script/index.js
CHANGED
package/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
|
-
const portfinder = require('portfinder');
|
|
2
|
+
const portfinder = require('portfinder-cp');
|
|
3
3
|
const proxy = require('express-http-proxy-cp');
|
|
4
4
|
const sudo = require("sudo-prompt-programfiles-x86");
|
|
5
5
|
const compressing = require('compressing');
|
|
@@ -1899,6 +1899,23 @@ class Server {
|
|
|
1899
1899
|
// configure from kernel.store
|
|
1900
1900
|
await this.syncConfig()
|
|
1901
1901
|
|
|
1902
|
+
// determine port if port is not passed in
|
|
1903
|
+
|
|
1904
|
+
if (options && options.port) {
|
|
1905
|
+
this.port = options.port
|
|
1906
|
+
} else {
|
|
1907
|
+
const primary_port = 80
|
|
1908
|
+
const secondary_port = 42000
|
|
1909
|
+
const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
|
|
1910
|
+
if (available) {
|
|
1911
|
+
this.port = primary_port
|
|
1912
|
+
} else {
|
|
1913
|
+
this.port = secondary_port
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
console.log("available port", this.port)
|
|
1918
|
+
|
|
1902
1919
|
// initialize kernel
|
|
1903
1920
|
await this.kernel.init({ port: this.port})
|
|
1904
1921
|
|
|
@@ -1906,7 +1923,7 @@ class Server {
|
|
|
1906
1923
|
if (this.kernel.homedir) {
|
|
1907
1924
|
let ex = await this.kernel.exists(this.kernel.homedir, "ENVIRONMENT")
|
|
1908
1925
|
if (!ex) {
|
|
1909
|
-
let str = Environment.ENV("system")
|
|
1926
|
+
let str = await Environment.ENV("system")
|
|
1910
1927
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
1911
1928
|
}
|
|
1912
1929
|
|
|
@@ -1916,6 +1933,8 @@ class Server {
|
|
|
1916
1933
|
}
|
|
1917
1934
|
}
|
|
1918
1935
|
|
|
1936
|
+
console.log("using port", this.port)
|
|
1937
|
+
|
|
1919
1938
|
|
|
1920
1939
|
// start proxy for Pinokio itself
|
|
1921
1940
|
// await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
|
|
@@ -2128,12 +2147,12 @@ class Server {
|
|
|
2128
2147
|
if (req.body.type) {
|
|
2129
2148
|
if (req.body.type === "local") {
|
|
2130
2149
|
await this.kernel.api.stopProxy({
|
|
2131
|
-
uri: `http://
|
|
2150
|
+
uri: `http://127.0.0.1:${this.port}`
|
|
2132
2151
|
})
|
|
2133
2152
|
} else if (req.body.type === "cloudflare") {
|
|
2134
2153
|
await this.cf.stop({
|
|
2135
2154
|
params: {
|
|
2136
|
-
uri: `http://
|
|
2155
|
+
uri: `http://127.0.0.1:${this.port}`
|
|
2137
2156
|
}
|
|
2138
2157
|
}, (e) => {
|
|
2139
2158
|
process.stdout.write(e.raw)
|
|
@@ -2153,11 +2172,22 @@ class Server {
|
|
|
2153
2172
|
*/
|
|
2154
2173
|
if (req.body.type) {
|
|
2155
2174
|
if (req.body.type === "local") {
|
|
2156
|
-
await this.kernel.
|
|
2175
|
+
let env = await Environment.get(this.kernel.homedir)
|
|
2176
|
+
if (env && env.PINOKIO_SHARE_LOCAL_PORT) {
|
|
2177
|
+
let port = env.PINOKIO_SHARE_LOCAL_PORT.trim()
|
|
2178
|
+
if (port.length > 0) {
|
|
2179
|
+
await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/", { port })
|
|
2180
|
+
} else {
|
|
2181
|
+
await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
|
|
2182
|
+
}
|
|
2183
|
+
} else {
|
|
2184
|
+
await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
|
|
2185
|
+
}
|
|
2186
|
+
console.log("started proxy")
|
|
2157
2187
|
} else if (req.body.type === "cloudflare") {
|
|
2158
2188
|
let { uri } = await this.cf.tunnel({
|
|
2159
2189
|
params: {
|
|
2160
|
-
uri: `http://
|
|
2190
|
+
uri: `http://127.0.0.1:${this.port}`
|
|
2161
2191
|
}
|
|
2162
2192
|
}, (e) => {
|
|
2163
2193
|
process.stdout.write(e.raw)
|
|
@@ -2173,6 +2203,7 @@ class Server {
|
|
|
2173
2203
|
this.app.post("/env", async (req, res) => {
|
|
2174
2204
|
let fullpath = path.resolve(this.kernel.homedir, req.body.filepath, "ENVIRONMENT")
|
|
2175
2205
|
let updated = req.body.vals
|
|
2206
|
+
console.log("updated", updated)
|
|
2176
2207
|
await Util.update_env(fullpath, updated)
|
|
2177
2208
|
res.json({})
|
|
2178
2209
|
})
|
|
@@ -2270,6 +2301,7 @@ class Server {
|
|
|
2270
2301
|
const keys = [
|
|
2271
2302
|
"PINOKIO_SHARE_CLOUDFLARE",
|
|
2272
2303
|
"PINOKIO_SHARE_LOCAL",
|
|
2304
|
+
"PINOKIO_SHARE_LOCAL_PORT"
|
|
2273
2305
|
]
|
|
2274
2306
|
for(let key of keys) {
|
|
2275
2307
|
if (!config[key]) {
|
|
@@ -235,6 +235,9 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
235
235
|
const passcode_el = document.querySelector("#passcode")
|
|
236
236
|
vals.PINOKIO_SHARE_PASSCODE = passcode_el.value
|
|
237
237
|
|
|
238
|
+
const port_el = document.querySelector("#local_port")
|
|
239
|
+
vals.PINOKIO_SHARE_LOCAL_PORT = port_el.value
|
|
240
|
+
|
|
238
241
|
let res = await fetch("/env", {
|
|
239
242
|
method: "POST",
|
|
240
243
|
headers: {
|
|
@@ -310,6 +313,16 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
310
313
|
<li>A new IP will be provided when local sharing is on, which can be used to access from any device on the same network.</li>
|
|
311
314
|
<li>You can manually configure this through the Configure menu (set PINOKIO_SHARE_LOCAL to true)</li>
|
|
312
315
|
</ul>
|
|
316
|
+
<div class='passcode'>
|
|
317
|
+
<h2>Custom Port (optional)</h2>
|
|
318
|
+
<ol>
|
|
319
|
+
<li><strong>No custom port:</strong> a random port will be generated automatically.</li>
|
|
320
|
+
<li><strong>Custom port:</strong> the local share network will be started at the specified port</li>
|
|
321
|
+
</ol>
|
|
322
|
+
<div class='row'>
|
|
323
|
+
<input id='local_port' type='text' value="<%=config.PINOKIO_SHARE_LOCAL_PORT || ''%>"/>
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
313
326
|
<% local_links.forEach((link) => { %>
|
|
314
327
|
<div class='shared'>
|
|
315
328
|
<a href="<%=link.url%>" target="_blank" features="browser"><%=link.url%></a>
|