pinokiod 2.1.2 → 2.1.5

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.
@@ -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
- const p = new Proxy()
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
  }
@@ -8,6 +8,7 @@ class P {
8
8
  "params": {
9
9
  "name",
10
10
  "uri": "http://localhost:8192",
11
+ "port": 3000,
11
12
  "ws": false
12
13
  }
13
14
  }
@@ -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
- type: ["system"],
8
- key: "HOMEBREW_CACHE",
9
- hidden: true,
10
- val: "./cache/HOMEBREW_CACHE"
11
- }, {
12
- type: ["system"],
13
- key: "XDG_CACHE_HOME",
14
- hidden: true,
15
- val: "./cache/XDG_CACHE_HOME"
16
- }, {
17
- type: ["system"],
18
- key: "PIP_CACHE_DIR",
19
- hidden: true,
20
- val: "./cache/PIP_CACHE_DIR"
21
- }, {
22
- type: ["system"],
23
- key: "PIP_TMPDIR",
24
- hidden: true,
25
- val: "./cache/PIP_TMPDIR"
26
- }, {
27
- type: ["system"],
28
- key: "TMPDIR",
29
- hidden: true,
30
- val: "./cache/TMPDIR"
31
- }, {
32
- type: ["system"],
33
- key: "TEMP",
34
- hidden: true,
35
- val: "./cache/TEMP"
36
- }, {
37
- type: ["system"],
38
- key: "TMP",
39
- hidden: true,
40
- val: "./cache/TMP"
41
- }, {
42
- type: ["system"],
43
- key: "XDG_DATA_HOME",
44
- hidden: true,
45
- val: "./cache/XDG_DATA_HOME"
46
- }, {
47
- type: ["system"],
48
- key: "XDG_CONFIG_HOME",
49
- hidden: true,
50
- val: "./cache/XDG_CONFIG_HOME"
51
- }, {
52
- type: ["system"],
53
- key: "XDG_STATE_HOME",
54
- hidden: true,
55
- val: "./cache/XDG_STATE_HOME"
56
- }, {
57
- type: ["system"],
58
- key: "PIP_CONFIG_FILE",
59
- hidden: true,
60
- val: "./pipconfig"
61
- }, {
62
- type: ["system"],
63
- key: "CONDARC",
64
- hidden: true,
65
- val: "./condarc"
66
- }, {
67
- type: ["system"],
68
- key: "PS1",
69
- hidden: true,
70
- val: "<<PINOKIO SHELL>> "
71
- }, {
72
- type: ["system"],
73
- key: "GRADIO_ANALYTICS_ENABLED",
74
- val: "False"
75
- }, {
76
- type: ["system"],
77
- key: "GRADIO_ALLOWED_PATHS",
78
- val: "./",
79
- comment: [
80
- "##########################################################################",
81
- "#",
82
- "# GRADIO_ALLOWED_PATHS",
83
- "#",
84
- "# This allows every Gradio app installed under Pinokio to serve files",
85
- "# outside of each app's root folder, which is useful for many cases.",
86
- "# Do not touch this unless you want to add additional paths",
87
- "#",
88
- "##########################################################################",
89
- ],
90
- }, {
91
- type: ["system"],
92
- key: "PINOKIO_SHARE_VAR",
93
- val: "url",
94
- comment: [
95
- "##########################################################################",
96
- "#",
97
- "# PINOKIO_SHARE_VAR",
98
- "#",
99
- "# When you set this local variable from any script, it will trigger Pinokio",
100
- "# share actions (local sharing, cloudflare, ...)",
101
- "#",
102
- "# You can customize whether to avoid this using PINOKIO_SHARE_CLOUDFLARE",
103
- "# and PINOKIO_SHARE_LOCAL",
104
- "#",
105
- "##########################################################################",
106
- ],
107
- }, {
108
- type: ["system", "app"],
109
- key: "PINOKIO_SHARE_CLOUDFLARE",
110
- val: "false",
111
- comment: [
112
- "##########################################################################",
113
- "#",
114
- "# PINOKIO_SHARE_CLOUDFLARE",
115
- "# Set this variable to share the app publicly via cloudflare tunnel.",
116
- "#",
117
- "##########################################################################",
118
- ]
119
- }, {
120
- type: ["app"],
121
- key: "PINOKIO_SHARE_PASSCODE",
122
- val: "",
123
- comment: [
124
- "##########################################################################",
125
- "#",
126
- "# PINOKIO_SHARE_PASSCODE",
127
- "#",
128
- "# By default, your publicly shared app will be 100% open to anyone",
129
- "# with the link via Cloudflare.",
130
- "#",
131
- "# You can add authorization by protecting it with a passcode.",
132
- "# Set this value, and any access to the app will require a pass code input",
133
- "#",
134
- "##########################################################################",
135
- ],
136
- }, {
137
- type: ["system", "app"],
138
- key: "PINOKIO_SCRIPT_DEFAULT",
139
- val: "true",
140
- comment: [
141
- "##########################################################################",
142
- "#",
143
- "# PINOKIO_SCRIPT_DEFAULT",
144
- "# If this variable is false, 'default': true menu items in pinokio.js",
145
- "# will NOT automatically run",
146
- "#",
147
- "##########################################################################",
148
- ]
149
- }, {
150
- type: ["system"],
151
- key: "PINOKIO_DRIVE",
152
- val: "./drive",
153
- comment: [
154
- "##########################################################################",
155
- "#",
156
- "# PINOKIO_DRIVE",
157
- "#",
158
- "# The virtual drive path.",
159
- "# Change it if you want to use a different path.",
160
- "# You can even enter an absolute path to use a folder outside of pinokio",
161
- "# or an entirely different disk drive",
162
- "#",
163
- "##########################################################################",
164
- ],
165
- }, {
166
- type: ["system"],
167
- key: "PINOKIO_PORT",
168
- val: (platform === "linux" ? "42000" : "80"),
169
- comment: [
170
- "##########################################################################",
171
- "#",
172
- "# PINOKIO_PORT",
173
- "#",
174
- "# The server port Pinokio will use. By default it's 80 but you can",
175
- "# Change it to anything else",
176
- "#",
177
- "##########################################################################",
178
- ],
179
- }, {
180
- type: ["system", "app"],
181
- key: "GRADIO_TEMP_DIR",
182
- val: "./cache/GRADIO_TEMP_DIR",
183
- comment: [
184
- "##########################################################################",
185
- "#",
186
- "# GRADIO_TEMP_DIR",
187
- "# All the files uploaded through gradio goes here.",
188
- "#",
189
- "# Delete this line to store the files under PINOKIO_HOME/cache/GRADIO_TEMPDIR",
190
- "# or change the path if you want to use a different path",
191
- "#",
192
- "##########################################################################",
193
- ],
194
- }, {
195
- type: ["system", "app"],
196
- key: "HF_HOME",
197
- val: "./cache/HF_HOME",
198
- comment: [
199
- "##########################################################################",
200
- "#",
201
- "# HF_HOME",
202
- "#",
203
- "# Huggingface cache",
204
- "# All the model files automatically downloaded through libraries like",
205
- "# diffusers, transformers, etc. will be stored under this path",
206
- "#",
207
- "# You can save disk space by deleting this line, which will store all",
208
- "# huggingface files under PINOKIO_HOME/cache/HF_HOME without redundancy.",
209
- "#",
210
- "##########################################################################",
211
- ],
212
- }, {
213
- type: ["system", "app"],
214
- key: "TORCH_HOME",
215
- val: "./cache/TORCH_HOME",
216
- comment: [
217
- "##########################################################################",
218
- "#",
219
- "# TORCH_HOME",
220
- "#",
221
- "# Torch hub cache",
222
- "# All the files automatically downloaded by pytorch will be stored here",
223
- "#",
224
- "# You can save disk space by deleting this line, which will store all",
225
- "# torch hub files under PINOKIO_HOME/cache/TORCH_HOME without redundancy.",
226
- "#",
227
- "##########################################################################",
228
- ],
229
- }, {
230
- type: ["system", "app"],
231
- key: "PINOKIO_SHARE_LOCAL",
232
- val: "false",
233
- comment: [
234
- "##########################################################################",
235
- "#",
236
- "# PINOKIO_SHARE_LOCAL",
237
- "# Set this variable to true to share the app on the local network.",
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
- return ENVS.filter((e) => {
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
- let uris = Object.keys(cf)
64
- for(let uri of uris) {
65
- await this.cloudflare.stop({
66
- parent: {
67
- path: scriptPath
68
- },
69
- params: { uri }
70
- }, (e) => {
71
- process.stdout.write(e.raw)
72
- }, this)
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
- return portfinder.getPortPromise({
142
- port: 42000
143
- })
144
- //return portfinder.getPortPromise()
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.2",
3
+ "version": "2.1.5",
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.9",
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.32",
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
@@ -38,9 +38,7 @@ class Store {
38
38
  }
39
39
  const server = new Server({
40
40
  //port: 42000,
41
- port: (platform === "linux" ? 42000 : 80),
42
41
  agent: "web",
43
42
  store: new Store()
44
43
  })
45
44
  server.start({ debug: true })
46
- //server.start()
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');
@@ -259,6 +259,7 @@ class Server {
259
259
  }
260
260
 
261
261
  const env = await this.kernel.env("api/" + name)
262
+ console.log(">> ENV", env)
262
263
 
263
264
  //res.render("browser", {
264
265
  res.render("browser-experimental", {
@@ -1899,6 +1900,23 @@ class Server {
1899
1900
  // configure from kernel.store
1900
1901
  await this.syncConfig()
1901
1902
 
1903
+ // determine port if port is not passed in
1904
+
1905
+ if (options && options.port) {
1906
+ this.port = options.port
1907
+ } else {
1908
+ const primary_port = 80
1909
+ const secondary_port = 42000
1910
+ const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
1911
+ if (available) {
1912
+ this.port = primary_port
1913
+ } else {
1914
+ this.port = secondary_port
1915
+ }
1916
+ }
1917
+
1918
+ console.log("available port", this.port)
1919
+
1902
1920
  // initialize kernel
1903
1921
  await this.kernel.init({ port: this.port})
1904
1922
 
@@ -1906,7 +1924,7 @@ class Server {
1906
1924
  if (this.kernel.homedir) {
1907
1925
  let ex = await this.kernel.exists(this.kernel.homedir, "ENVIRONMENT")
1908
1926
  if (!ex) {
1909
- let str = Environment.ENV("system")
1927
+ let str = await Environment.ENV("system")
1910
1928
  await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
1911
1929
  }
1912
1930
 
@@ -1916,6 +1934,8 @@ class Server {
1916
1934
  }
1917
1935
  }
1918
1936
 
1937
+ console.log("using port", this.port)
1938
+
1919
1939
 
1920
1940
  // start proxy for Pinokio itself
1921
1941
  // await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
@@ -2128,12 +2148,12 @@ class Server {
2128
2148
  if (req.body.type) {
2129
2149
  if (req.body.type === "local") {
2130
2150
  await this.kernel.api.stopProxy({
2131
- uri: `http://localhost:${this.port}`
2151
+ uri: `http://127.0.0.1:${this.port}`
2132
2152
  })
2133
2153
  } else if (req.body.type === "cloudflare") {
2134
2154
  await this.cf.stop({
2135
2155
  params: {
2136
- uri: `http://localhost:${this.port}`
2156
+ uri: `http://127.0.0.1:${this.port}`
2137
2157
  }
2138
2158
  }, (e) => {
2139
2159
  process.stdout.write(e.raw)
@@ -2153,11 +2173,22 @@ class Server {
2153
2173
  */
2154
2174
  if (req.body.type) {
2155
2175
  if (req.body.type === "local") {
2156
- await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
2176
+ let env = await Environment.get(this.kernel.homedir)
2177
+ if (env && env.PINOKIO_SHARE_LOCAL_PORT) {
2178
+ let port = env.PINOKIO_SHARE_LOCAL_PORT.trim()
2179
+ if (port.length > 0) {
2180
+ await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/", { port })
2181
+ } else {
2182
+ await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
2183
+ }
2184
+ } else {
2185
+ await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
2186
+ }
2187
+ console.log("started proxy")
2157
2188
  } else if (req.body.type === "cloudflare") {
2158
2189
  let { uri } = await this.cf.tunnel({
2159
2190
  params: {
2160
- uri: `http://localhost:${this.port}`
2191
+ uri: `http://127.0.0.1:${this.port}`
2161
2192
  }
2162
2193
  }, (e) => {
2163
2194
  process.stdout.write(e.raw)
@@ -2173,6 +2204,7 @@ class Server {
2173
2204
  this.app.post("/env", async (req, res) => {
2174
2205
  let fullpath = path.resolve(this.kernel.homedir, req.body.filepath, "ENVIRONMENT")
2175
2206
  let updated = req.body.vals
2207
+ console.log("updated", updated)
2176
2208
  await Util.update_env(fullpath, updated)
2177
2209
  res.json({})
2178
2210
  })
@@ -2270,6 +2302,7 @@ class Server {
2270
2302
  const keys = [
2271
2303
  "PINOKIO_SHARE_CLOUDFLARE",
2272
2304
  "PINOKIO_SHARE_LOCAL",
2305
+ "PINOKIO_SHARE_LOCAL_PORT"
2273
2306
  ]
2274
2307
  for(let key of keys) {
2275
2308
  if (!config[key]) {
@@ -22,7 +22,7 @@ html {
22
22
 
23
23
  body {
24
24
  height: 100%;
25
- overflow: hidden;
25
+ overflow: auto;
26
26
  background: rgb(44, 29, 22);
27
27
  display: flex;
28
28
  flex-direction: column;
@@ -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>