pinokiod 2.1.8 → 2.1.10
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/bin/brew.js +3 -0
- package/kernel/bin/index.js +8 -0
- package/kernel/environment.js +49 -31
- package/kernel/index.js +1 -1
- package/package.json +1 -1
- package/server/index.js +97 -126
- package/server/views/500.ejs +50 -0
- package/server/views/index.ejs +1 -1
- package/server/views/settings.ejs +1 -1
package/kernel/bin/brew.js
CHANGED
|
@@ -27,6 +27,8 @@ class Brew {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async installed() {
|
|
30
|
+
return this.kernel.bin.brew_installed
|
|
31
|
+
/*
|
|
30
32
|
let e = await this.kernel.bin.exists("homebrew")
|
|
31
33
|
|
|
32
34
|
let { stdout }= await this.kernel.bin.exec({ message: "xcode-select -p" }, (stream) => { })
|
|
@@ -34,6 +36,7 @@ class Brew {
|
|
|
34
36
|
console.log({ e, e2, stdout })
|
|
35
37
|
|
|
36
38
|
return e && e2
|
|
39
|
+
*/
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
uninstall(req, ondata) {
|
package/kernel/bin/index.js
CHANGED
|
@@ -350,6 +350,14 @@ class Bin {
|
|
|
350
350
|
|
|
351
351
|
console.log("this.installed", this.installed)
|
|
352
352
|
|
|
353
|
+
// check brew_installed
|
|
354
|
+
console.log("checking brew installed")
|
|
355
|
+
let e = await this.kernel.bin.exists("homebrew")
|
|
356
|
+
let { stdout }= await this.kernel.bin.exec({ message: "xcode-select -p" }, (stream) => { })
|
|
357
|
+
let e2 = /(.*Library.*Developer.*CommandLineTools.*|.*Xcode.*Developer.*)/gi.test(stdout)
|
|
358
|
+
console.log({ e, e2, stdout })
|
|
359
|
+
this.brew_installed = e && e2
|
|
360
|
+
|
|
353
361
|
|
|
354
362
|
this.installed_initialized = true
|
|
355
363
|
|
package/kernel/environment.js
CHANGED
|
@@ -5,15 +5,15 @@ const fs = require('fs')
|
|
|
5
5
|
const Util = require('./util')
|
|
6
6
|
const platform = os.platform()
|
|
7
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
|
-
}
|
|
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
17
|
return [{
|
|
18
18
|
type: ["system"],
|
|
19
19
|
key: "HOMEBREW_CACHE",
|
|
@@ -173,20 +173,20 @@ const ENVS = async () => {
|
|
|
173
173
|
"#",
|
|
174
174
|
"##########################################################################",
|
|
175
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
|
-
],
|
|
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
190
|
}, {
|
|
191
191
|
type: ["system", "app"],
|
|
192
192
|
key: "GRADIO_TEMP_DIR",
|
|
@@ -281,24 +281,42 @@ const ENVS = async () => {
|
|
|
281
281
|
//}
|
|
282
282
|
|
|
283
283
|
// type := system|app
|
|
284
|
-
const ENV = async (type) => {
|
|
284
|
+
const ENV = async (type, homedir) => {
|
|
285
285
|
const envs = await ENVS()
|
|
286
|
-
|
|
286
|
+
let filtered_envs = envs.filter((e) => {
|
|
287
287
|
return e.type.includes(type)
|
|
288
|
-
})
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
let lines = []
|
|
291
|
+
for(let e of filtered_envs) {
|
|
289
292
|
let comment = ""
|
|
290
293
|
if (e.comment && Array.isArray(e.comment)) {
|
|
291
294
|
comment = "\n" + e.comment.join("\n") + "\n"
|
|
292
295
|
}
|
|
293
296
|
|
|
294
|
-
let
|
|
297
|
+
let val
|
|
295
298
|
if (typeof e.val === "function") {
|
|
296
|
-
|
|
299
|
+
val = e.val(type)
|
|
297
300
|
} else {
|
|
298
|
-
|
|
301
|
+
val = e.val
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// if app environment,
|
|
305
|
+
// if e.key exists on system env, use that
|
|
306
|
+
// if e.key does NOT exist on system env,
|
|
307
|
+
if (type === 'app') {
|
|
308
|
+
let system_env = await get(homedir)
|
|
309
|
+
if (e.key in system_env) {
|
|
310
|
+
console.log(`original ${e.key}=${val}`)
|
|
311
|
+
val = system_env[e.key]
|
|
312
|
+
console.log(`inherited from system_env: ${e.key}=${val}`)
|
|
313
|
+
}
|
|
299
314
|
}
|
|
300
|
-
|
|
301
|
-
|
|
315
|
+
|
|
316
|
+
let kv = `${e.key}=${val}`
|
|
317
|
+
lines.push(comment+kv)
|
|
318
|
+
}
|
|
319
|
+
return lines.join("\n")
|
|
302
320
|
}
|
|
303
321
|
const init_folders = async (homedir) => {
|
|
304
322
|
const current_env = await get(homedir)
|
package/kernel/index.js
CHANGED
|
@@ -296,7 +296,7 @@ class Kernel {
|
|
|
296
296
|
// if it doesn't exist, write to ~/pinokio/ENVIRONMENT
|
|
297
297
|
let e = await this.exists(this.homedir, "ENVIRONMENT")
|
|
298
298
|
if (!e) {
|
|
299
|
-
let str = await Environment.ENV("system")
|
|
299
|
+
let str = await Environment.ENV("system", this.homedir)
|
|
300
300
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
301
301
|
}
|
|
302
302
|
// 2. mkdir all the folders if not already created
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -28,6 +28,10 @@ const multer = require('multer');
|
|
|
28
28
|
|
|
29
29
|
const ejs = require('ejs');
|
|
30
30
|
|
|
31
|
+
const ex = fn => (req, res, next) => {
|
|
32
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
33
|
+
};
|
|
34
|
+
|
|
31
35
|
|
|
32
36
|
|
|
33
37
|
|
|
@@ -184,7 +188,7 @@ class Server {
|
|
|
184
188
|
// if _ENVIRONMENT exists,
|
|
185
189
|
let _environment = this.kernel.path(env_dir_path, "_ENVIRONMENT")
|
|
186
190
|
let _exists = await this.exists(_environment)
|
|
187
|
-
let content = await Environment.ENV("app")
|
|
191
|
+
let content = await Environment.ENV("app", this.kernel.homedir)
|
|
188
192
|
if (_exists) {
|
|
189
193
|
let _environmentStr = await fs.promises.readFile(_environment, "utf8")
|
|
190
194
|
await fs.promises.writeFile(current, _environmentStr + "\n\n\n" + content)
|
|
@@ -388,7 +392,7 @@ class Server {
|
|
|
388
392
|
// if environment.json doesn't exist,
|
|
389
393
|
let exists = await this.exists(filepath)
|
|
390
394
|
if (!exists) {
|
|
391
|
-
let content = await Environment.ENV("app")
|
|
395
|
+
let content = await Environment.ENV("app", this.kernel.homedir)
|
|
392
396
|
await fs.promises.writeFile(filepath, content)
|
|
393
397
|
}
|
|
394
398
|
}
|
|
@@ -455,7 +459,9 @@ class Server {
|
|
|
455
459
|
install_required = false
|
|
456
460
|
for(let i=0; i<requirements.length; i++) {
|
|
457
461
|
let r = requirements[i]
|
|
462
|
+
console.log("r", r)
|
|
458
463
|
let installed = await this.installed(r)
|
|
464
|
+
console.log("installed", installed)
|
|
459
465
|
requirements[i].installed = installed
|
|
460
466
|
if (!installed) {
|
|
461
467
|
install_required = true
|
|
@@ -826,54 +832,6 @@ class Server {
|
|
|
826
832
|
|
|
827
833
|
|
|
828
834
|
let mem = this.getMemory(filepath)
|
|
829
|
-
// let localMem = this.kernel.memory.local[filepath]
|
|
830
|
-
// let globalMem = this.kernel.memory.global[filepath]
|
|
831
|
-
//
|
|
832
|
-
// let mem = []
|
|
833
|
-
// let localhosts = ["localhost", "127.0.0.1", "0.0.0.0"]
|
|
834
|
-
// for(let key in localMem) {
|
|
835
|
-
// let val = localMem[key]
|
|
836
|
-
// // check for localhost url
|
|
837
|
-
// let localhost = false
|
|
838
|
-
// let tunnel
|
|
839
|
-
// try {
|
|
840
|
-
// let url = new URL(val)
|
|
841
|
-
// if (localhosts.includes(url.hostname)) {
|
|
842
|
-
// localhost = true
|
|
843
|
-
// if (this.tunnels[val]) {
|
|
844
|
-
// tunnel = this.tunnels[val].url
|
|
845
|
-
// }
|
|
846
|
-
// }
|
|
847
|
-
// } catch (e) { }
|
|
848
|
-
// mem.push({
|
|
849
|
-
// type: "local",
|
|
850
|
-
// key,
|
|
851
|
-
// val,
|
|
852
|
-
// tunnel,
|
|
853
|
-
// localhost,
|
|
854
|
-
// })
|
|
855
|
-
// }
|
|
856
|
-
// for(let key in globalMem) {
|
|
857
|
-
// let val = globalMem[key]
|
|
858
|
-
// let localhost = false
|
|
859
|
-
// let tunnel
|
|
860
|
-
// try {
|
|
861
|
-
// let url = new URL(val)
|
|
862
|
-
// if (localhosts.includes(url.hostname)) {
|
|
863
|
-
// localhost = true
|
|
864
|
-
// if (this.tunnels[val]) {
|
|
865
|
-
// tunnel = this.tunnels[val].url
|
|
866
|
-
// }
|
|
867
|
-
// }
|
|
868
|
-
// } catch (e) { }
|
|
869
|
-
// mem.push({
|
|
870
|
-
// type: "global",
|
|
871
|
-
// key,
|
|
872
|
-
// val,
|
|
873
|
-
// tunnel,
|
|
874
|
-
// localhost,
|
|
875
|
-
// })
|
|
876
|
-
// }
|
|
877
835
|
let edu = new URL("http://localhost" + req.originalUrl)
|
|
878
836
|
edu.searchParams.set("mode", "source")
|
|
879
837
|
let editorUrl = edu.pathname + edu.search
|
|
@@ -1907,6 +1865,7 @@ class Server {
|
|
|
1907
1865
|
const primary_port = 80
|
|
1908
1866
|
const secondary_port = 42000
|
|
1909
1867
|
const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
|
|
1868
|
+
console.log("check available", { primary_port, available })
|
|
1910
1869
|
if (available) {
|
|
1911
1870
|
this.port = primary_port
|
|
1912
1871
|
} else {
|
|
@@ -1923,14 +1882,14 @@ class Server {
|
|
|
1923
1882
|
if (this.kernel.homedir) {
|
|
1924
1883
|
let ex = await this.kernel.exists(this.kernel.homedir, "ENVIRONMENT")
|
|
1925
1884
|
if (!ex) {
|
|
1926
|
-
let str = await Environment.ENV("system")
|
|
1885
|
+
let str = await Environment.ENV("system", this.kernel.homedir)
|
|
1927
1886
|
await fs.promises.writeFile(path.resolve(this.homedir, "ENVIRONMENT"), str)
|
|
1928
1887
|
}
|
|
1929
1888
|
|
|
1930
|
-
let env = await Environment.get(this.kernel.homedir)
|
|
1931
|
-
if (env && env.PINOKIO_PORT) {
|
|
1932
|
-
this.port = env.PINOKIO_PORT
|
|
1933
|
-
}
|
|
1889
|
+
// let env = await Environment.get(this.kernel.homedir)
|
|
1890
|
+
// if (env && env.PINOKIO_PORT) {
|
|
1891
|
+
// this.port = env.PINOKIO_PORT
|
|
1892
|
+
// }
|
|
1934
1893
|
}
|
|
1935
1894
|
|
|
1936
1895
|
console.log("using port", this.port)
|
|
@@ -2009,7 +1968,7 @@ class Server {
|
|
|
2009
1968
|
|
|
2010
1969
|
//let home = this.kernel.homedir
|
|
2011
1970
|
let home = this.kernel.store.get("home")
|
|
2012
|
-
this.app.get("/", async (req, res) => {
|
|
1971
|
+
this.app.get("/", ex(async (req, res) => {
|
|
2013
1972
|
if (req.query.mode !== "settings" && !home) {
|
|
2014
1973
|
res.redirect("/?mode=settings")
|
|
2015
1974
|
return
|
|
@@ -2136,9 +2095,9 @@ class Server {
|
|
|
2136
2095
|
// agent: this.agent,
|
|
2137
2096
|
// })
|
|
2138
2097
|
// }
|
|
2139
|
-
})
|
|
2098
|
+
}))
|
|
2140
2099
|
|
|
2141
|
-
this.app.post("/unpublish", async (req, res) => {
|
|
2100
|
+
this.app.post("/unpublish", ex(async (req, res) => {
|
|
2142
2101
|
/*
|
|
2143
2102
|
req.body := {
|
|
2144
2103
|
type: "local"|"cloudflare"
|
|
@@ -2163,8 +2122,8 @@ class Server {
|
|
|
2163
2122
|
} else {
|
|
2164
2123
|
res.json({ error: "type must be 'local' or 'cloudflare'" })
|
|
2165
2124
|
}
|
|
2166
|
-
})
|
|
2167
|
-
this.app.post("/publish", async (req, res) => {
|
|
2125
|
+
}))
|
|
2126
|
+
this.app.post("/publish", ex(async (req, res) => {
|
|
2168
2127
|
/*
|
|
2169
2128
|
req.body := {
|
|
2170
2129
|
type: "local"|"cloudflare"
|
|
@@ -2199,14 +2158,14 @@ class Server {
|
|
|
2199
2158
|
} else {
|
|
2200
2159
|
res.json({ error: "type must be 'local' or 'cloudflare'" })
|
|
2201
2160
|
}
|
|
2202
|
-
})
|
|
2203
|
-
this.app.post("/env", async (req, res) => {
|
|
2161
|
+
}))
|
|
2162
|
+
this.app.post("/env", ex(async (req, res) => {
|
|
2204
2163
|
let fullpath = path.resolve(this.kernel.homedir, req.body.filepath, "ENVIRONMENT")
|
|
2205
2164
|
let updated = req.body.vals
|
|
2206
2165
|
await Util.update_env(fullpath, updated)
|
|
2207
2166
|
res.json({})
|
|
2208
|
-
})
|
|
2209
|
-
this.app.get("/env", async (req, res) => {
|
|
2167
|
+
}))
|
|
2168
|
+
this.app.get("/env", ex(async (req, res) => {
|
|
2210
2169
|
let env_path = path.resolve(this.kernel.homedir)
|
|
2211
2170
|
await this.init_env(env_path)
|
|
2212
2171
|
|
|
@@ -2227,8 +2186,8 @@ class Server {
|
|
|
2227
2186
|
filepath,
|
|
2228
2187
|
agent: this.agent,
|
|
2229
2188
|
})
|
|
2230
|
-
})
|
|
2231
|
-
this.app.get("/env/*", async (req, res) => {
|
|
2189
|
+
}))
|
|
2190
|
+
this.app.get("/env/*", ex(async (req, res) => {
|
|
2232
2191
|
|
|
2233
2192
|
let env_path = req.params[0]
|
|
2234
2193
|
await this.init_env(env_path)
|
|
@@ -2259,8 +2218,8 @@ class Server {
|
|
|
2259
2218
|
filepath,
|
|
2260
2219
|
agent: this.agent,
|
|
2261
2220
|
})
|
|
2262
|
-
})
|
|
2263
|
-
this.app.get("/pre/api/:name", async (req, res) => {
|
|
2221
|
+
}))
|
|
2222
|
+
this.app.get("/pre/api/:name", ex(async (req, res) => {
|
|
2264
2223
|
let p = path.resolve(this.kernel.homedir, "api", req.params.name, "pinokio.js")
|
|
2265
2224
|
let config = (await this.kernel.loader.load(p)).resolved
|
|
2266
2225
|
if (config && config.pre) {
|
|
@@ -2277,8 +2236,8 @@ class Server {
|
|
|
2277
2236
|
} else {
|
|
2278
2237
|
res.redirect("/env/" + req.params.name + "?init=true")
|
|
2279
2238
|
}
|
|
2280
|
-
})
|
|
2281
|
-
this.app.get("/initialize/:name", async (req, res) => {
|
|
2239
|
+
}))
|
|
2240
|
+
this.app.get("/initialize/:name", ex(async (req, res) => {
|
|
2282
2241
|
let p = path.resolve(this.kernel.homedir, "api", req.params.name, "pinokio.js")
|
|
2283
2242
|
let config = (await this.kernel.loader.load(p)).resolved
|
|
2284
2243
|
if (config) {
|
|
@@ -2294,8 +2253,8 @@ class Server {
|
|
|
2294
2253
|
// if pinokio.js doesn't exist, send to /browser/:name
|
|
2295
2254
|
res.redirect(`/pinokio/browser/${req.params.name}`)
|
|
2296
2255
|
}
|
|
2297
|
-
})
|
|
2298
|
-
this.app.get("/share/:name", async (req, res) => {
|
|
2256
|
+
}))
|
|
2257
|
+
this.app.get("/share/:name", ex(async (req, res) => {
|
|
2299
2258
|
let filepath = path.resolve(this.kernel.homedir, "api", req.params.name, "ENVIRONMENT")
|
|
2300
2259
|
//let filepath = path.resolve(this.kernel.homedir, req.params[0])
|
|
2301
2260
|
const config = await Util.parse_env(filepath)
|
|
@@ -2351,8 +2310,8 @@ class Server {
|
|
|
2351
2310
|
filepath,
|
|
2352
2311
|
agent: this.agent,
|
|
2353
2312
|
})
|
|
2354
|
-
})
|
|
2355
|
-
this.app.get("/edit/*", async (req, res) => {
|
|
2313
|
+
}))
|
|
2314
|
+
this.app.get("/edit/*", ex(async (req, res) => {
|
|
2356
2315
|
let pathComponents = req.params[0].split("/")
|
|
2357
2316
|
let filepath = path.resolve(this.kernel.homedir, req.params[0])
|
|
2358
2317
|
const content = await fs.promises.readFile(filepath, "utf8")
|
|
@@ -2363,13 +2322,13 @@ class Server {
|
|
|
2363
2322
|
content,
|
|
2364
2323
|
agent: this.agent,
|
|
2365
2324
|
})
|
|
2366
|
-
})
|
|
2367
|
-
this.app.get("/script/:name", (req, res) => {
|
|
2325
|
+
}))
|
|
2326
|
+
this.app.get("/script/:name", ex((req, res) => {
|
|
2368
2327
|
if (req.params.name === "start") {
|
|
2369
2328
|
res.json(this.startScripts)
|
|
2370
2329
|
}
|
|
2371
|
-
})
|
|
2372
|
-
this.app.get("/raw/*", (req, res) => {
|
|
2330
|
+
}))
|
|
2331
|
+
this.app.get("/raw/*", ex((req, res) => {
|
|
2373
2332
|
let pathComponents = req.params[0].split("/")
|
|
2374
2333
|
let filepath = this.kernel.path("api", ...pathComponents)
|
|
2375
2334
|
try {
|
|
@@ -2382,8 +2341,8 @@ class Server {
|
|
|
2382
2341
|
} catch (e) {
|
|
2383
2342
|
res.status(404).send(e.message);
|
|
2384
2343
|
}
|
|
2385
|
-
})
|
|
2386
|
-
this.app.get("/_api/*", async (req, res) => {
|
|
2344
|
+
}))
|
|
2345
|
+
this.app.get("/_api/*", ex(async (req, res) => {
|
|
2387
2346
|
let pathComponents = req.params[0].split("/")
|
|
2388
2347
|
req.query.mode = "source"
|
|
2389
2348
|
try {
|
|
@@ -2391,16 +2350,16 @@ class Server {
|
|
|
2391
2350
|
} catch (e) {
|
|
2392
2351
|
res.status(404).send(e.message)
|
|
2393
2352
|
}
|
|
2394
|
-
})
|
|
2395
|
-
this.app.get("/api/*", async (req, res) => {
|
|
2353
|
+
}))
|
|
2354
|
+
this.app.get("/api/*", ex(async (req, res) => {
|
|
2396
2355
|
let pathComponents = req.params[0].split("/")
|
|
2397
2356
|
try {
|
|
2398
2357
|
await this.render(req, res, pathComponents)
|
|
2399
2358
|
} catch (e) {
|
|
2400
2359
|
res.status(404).send(e.message)
|
|
2401
2360
|
}
|
|
2402
|
-
})
|
|
2403
|
-
this.app.get("/pinokio/sidebar/:name", async (req, res) => {
|
|
2361
|
+
}))
|
|
2362
|
+
this.app.get("/pinokio/sidebar/:name", ex(async (req, res) => {
|
|
2404
2363
|
let name = req.params.name
|
|
2405
2364
|
let app_path = this.kernel.path("api", name, "pinokio.js")
|
|
2406
2365
|
let rawpath = "/api/" + name
|
|
@@ -2453,12 +2412,12 @@ class Server {
|
|
|
2453
2412
|
})
|
|
2454
2413
|
*/
|
|
2455
2414
|
|
|
2456
|
-
})
|
|
2457
|
-
this.app.get("/pinokio/memory", (req, res) => {
|
|
2415
|
+
}))
|
|
2416
|
+
this.app.get("/pinokio/memory", ex((req, res) => {
|
|
2458
2417
|
let filepath = req.query.filepath
|
|
2459
2418
|
let mem = this.getMemory(filepath)
|
|
2460
2419
|
res.json(mem)
|
|
2461
|
-
})
|
|
2420
|
+
}))
|
|
2462
2421
|
// this.app.post("/pinokio/tunnel", async (req, res) => {
|
|
2463
2422
|
// let port
|
|
2464
2423
|
// let local_host
|
|
@@ -2510,11 +2469,11 @@ class Server {
|
|
|
2510
2469
|
// res.json({ error: e.message })
|
|
2511
2470
|
// }
|
|
2512
2471
|
// })
|
|
2513
|
-
this.app.post("/pinokio/tabs", async (req, res) => {
|
|
2472
|
+
this.app.post("/pinokio/tabs", ex(async (req, res) => {
|
|
2514
2473
|
this.tabs[req.body.name] = req.body.tabs
|
|
2515
2474
|
res.json({ success: true })
|
|
2516
|
-
})
|
|
2517
|
-
this.app.get("/pinokio/browser", async (req, res) => {
|
|
2475
|
+
}))
|
|
2476
|
+
this.app.get("/pinokio/browser", ex(async (req, res) => {
|
|
2518
2477
|
if (req.query && req.query.uri) {
|
|
2519
2478
|
let uri = req.query.uri
|
|
2520
2479
|
let p = this.kernel.api.resolveBrowserPath(uri)
|
|
@@ -2522,19 +2481,19 @@ class Server {
|
|
|
2522
2481
|
} else {
|
|
2523
2482
|
res.redirect("/")
|
|
2524
2483
|
}
|
|
2525
|
-
})
|
|
2526
|
-
this.app.get("/pinokio/launch/:name", async (req, res) => {
|
|
2484
|
+
}))
|
|
2485
|
+
this.app.get("/pinokio/launch/:name", ex(async (req, res) => {
|
|
2527
2486
|
this.chrome(req, res, "launch")
|
|
2528
|
-
})
|
|
2529
|
-
this.app.get("/pinokio/browser/:name/browse", async (req, res) => {
|
|
2487
|
+
}))
|
|
2488
|
+
this.app.get("/pinokio/browser/:name/browse", ex(async (req, res) => {
|
|
2530
2489
|
console.log("browse mode")
|
|
2531
2490
|
this.chrome(req, res, "browse")
|
|
2532
|
-
})
|
|
2533
|
-
this.app.get("/pinokio/browser/:name", async (req, res) => {
|
|
2491
|
+
}))
|
|
2492
|
+
this.app.get("/pinokio/browser/:name", ex(async (req, res) => {
|
|
2534
2493
|
console.log("run mode")
|
|
2535
2494
|
this.chrome(req, res, "run")
|
|
2536
|
-
})
|
|
2537
|
-
this.app.post("/pinokio/delete", async (req, res) => {
|
|
2495
|
+
}))
|
|
2496
|
+
this.app.post("/pinokio/delete", ex(async (req, res) => {
|
|
2538
2497
|
try {
|
|
2539
2498
|
if (req.body.type === 'bin') {
|
|
2540
2499
|
let folderPath = this.kernel.path("bin")
|
|
@@ -2565,7 +2524,7 @@ class Server {
|
|
|
2565
2524
|
} catch(err) {
|
|
2566
2525
|
res.json({ error: err.stack })
|
|
2567
2526
|
}
|
|
2568
|
-
})
|
|
2527
|
+
}))
|
|
2569
2528
|
// this.app.get("/pinokio/shell_state", (req, res) => {
|
|
2570
2529
|
// let states = this.kernel.shell.shells.map((s) => {
|
|
2571
2530
|
// return {
|
|
@@ -2592,12 +2551,12 @@ class Server {
|
|
|
2592
2551
|
// gpus: this.kernel.gpus
|
|
2593
2552
|
// }
|
|
2594
2553
|
// })
|
|
2595
|
-
this.app.get("/pinokio/logs.zip", (req, res) => {
|
|
2554
|
+
this.app.get("/pinokio/logs.zip", ex((req, res) => {
|
|
2596
2555
|
let zipPath = this.kernel.path("logs.zip")
|
|
2597
2556
|
console.log("sendFile", zipPath)
|
|
2598
2557
|
res.download(zipPath)
|
|
2599
|
-
})
|
|
2600
|
-
this.app.post("/pinokio/log", async (req, res) => {
|
|
2558
|
+
}))
|
|
2559
|
+
this.app.post("/pinokio/log", ex(async (req, res) => {
|
|
2601
2560
|
|
|
2602
2561
|
|
|
2603
2562
|
let states = this.kernel.shell.shells.map((s) => {
|
|
@@ -2641,21 +2600,21 @@ class Server {
|
|
|
2641
2600
|
let zipPath = this.kernel.path("logs.zip")
|
|
2642
2601
|
await compressing.zip.compressDir(folder, zipPath)
|
|
2643
2602
|
res.json({ success: true })
|
|
2644
|
-
})
|
|
2645
|
-
this.app.get("/pinokio/port", async (req, res) => {
|
|
2603
|
+
}))
|
|
2604
|
+
this.app.get("/pinokio/port", ex(async (req, res) => {
|
|
2646
2605
|
let port = await this.kernel.port()
|
|
2647
2606
|
res.json({ result: port })
|
|
2648
|
-
})
|
|
2649
|
-
this.app.get("/pinokio/download", (req, res) => {
|
|
2607
|
+
}))
|
|
2608
|
+
this.app.get("/pinokio/download", ex((req, res) => {
|
|
2650
2609
|
let queryStr = new URLSearchParams(req.query).toString()
|
|
2651
2610
|
res.redirect("/?mode=download&" + queryStr)
|
|
2652
|
-
})
|
|
2653
|
-
this.app.post("/pinokio/install", (req, res) => {
|
|
2611
|
+
}))
|
|
2612
|
+
this.app.post("/pinokio/install", ex((req, res) => {
|
|
2654
2613
|
req.session.requirements = req.body.requirements
|
|
2655
2614
|
req.session.callback = req.body.callback
|
|
2656
2615
|
res.redirect("/pinokio/install")
|
|
2657
|
-
})
|
|
2658
|
-
this.app.get("/pinokio/install", (req, res) => {
|
|
2616
|
+
}))
|
|
2617
|
+
this.app.get("/pinokio/install", ex((req, res) => {
|
|
2659
2618
|
let requirements = req.session.requirements
|
|
2660
2619
|
let callback = req.session.callback
|
|
2661
2620
|
req.session.requirements = null
|
|
@@ -2670,8 +2629,8 @@ class Server {
|
|
|
2670
2629
|
requirements,
|
|
2671
2630
|
callback
|
|
2672
2631
|
})
|
|
2673
|
-
})
|
|
2674
|
-
this.app.get("/pinokio", (req, res) => {
|
|
2632
|
+
}))
|
|
2633
|
+
this.app.get("/pinokio", ex((req, res) => {
|
|
2675
2634
|
// parse the uri & path
|
|
2676
2635
|
let {uri, ...query} = req.query
|
|
2677
2636
|
let querystring = new URLSearchParams(query).toString()
|
|
@@ -2680,7 +2639,7 @@ class Server {
|
|
|
2680
2639
|
webpath = webpath + "?" + querystring
|
|
2681
2640
|
}
|
|
2682
2641
|
res.redirect(webpath)
|
|
2683
|
-
})
|
|
2642
|
+
}))
|
|
2684
2643
|
/*
|
|
2685
2644
|
SYNTAX
|
|
2686
2645
|
fs.uri(<bin|api>, path)
|
|
@@ -2693,7 +2652,7 @@ class Server {
|
|
|
2693
2652
|
1. Git URI: http://localhost:4200/pinokio/fs?drive=api&path=https://github.com/cocktailpeanut/llamacpp.pinokio.git/icon.png
|
|
2694
2653
|
2. Local path: http://localhost:4200/pinokio/fs?drive=api&path=test/icon.png
|
|
2695
2654
|
*/
|
|
2696
|
-
this.app.get("/pinokio/fs", (req, res) => {
|
|
2655
|
+
this.app.get("/pinokio/fs", ex((req, res) => {
|
|
2697
2656
|
// serve reaw files
|
|
2698
2657
|
if (req.query && req.query.drive && req.query.path) {
|
|
2699
2658
|
let p
|
|
@@ -2715,8 +2674,8 @@ class Server {
|
|
|
2715
2674
|
} else {
|
|
2716
2675
|
res.status(404).send("Missing attribute: path")
|
|
2717
2676
|
}
|
|
2718
|
-
})
|
|
2719
|
-
this.app.post("/pinokio/fs", this.upload.any(), async (req, res) => {
|
|
2677
|
+
}))
|
|
2678
|
+
this.app.post("/pinokio/fs", this.upload.any(), ex(async (req, res) => {
|
|
2720
2679
|
/*
|
|
2721
2680
|
Packet format:
|
|
2722
2681
|
types: <argument types>
|
|
@@ -2872,21 +2831,21 @@ class Server {
|
|
|
2872
2831
|
res.json({ error: "Required attributes: path, method, types" })
|
|
2873
2832
|
}
|
|
2874
2833
|
|
|
2875
|
-
})
|
|
2876
|
-
this.app.get("/pinokio/requirements_ready", (req, res) => {
|
|
2834
|
+
}))
|
|
2835
|
+
this.app.get("/pinokio/requirements_ready", ex((req, res) => {
|
|
2877
2836
|
|
|
2878
2837
|
let requirements_pending = !this.kernel.bin.installed_initialized
|
|
2879
2838
|
console.log({ requirements_pending })
|
|
2880
2839
|
res.json({ requirements_pending })
|
|
2881
|
-
})
|
|
2882
|
-
this.app.get("/check", (req, res) => {
|
|
2840
|
+
}))
|
|
2841
|
+
this.app.get("/check", ex((req, res) => {
|
|
2883
2842
|
res.json({ success: true })
|
|
2884
|
-
})
|
|
2885
|
-
this.app.post("/restart", async (req, res) => {
|
|
2843
|
+
}))
|
|
2844
|
+
this.app.post("/restart", ex(async (req, res) => {
|
|
2886
2845
|
console.log("post /restart")
|
|
2887
|
-
this.start(this.debug)
|
|
2888
|
-
})
|
|
2889
|
-
this.app.post("/config", async (req, res) => {
|
|
2846
|
+
this.start({ debug: this.debug, browser: this.browser })
|
|
2847
|
+
}))
|
|
2848
|
+
this.app.post("/config", ex(async (req, res) => {
|
|
2890
2849
|
console.log("/config", { body: req.body })
|
|
2891
2850
|
try {
|
|
2892
2851
|
await this.setConfig(req.body)
|
|
@@ -2896,7 +2855,19 @@ class Server {
|
|
|
2896
2855
|
}
|
|
2897
2856
|
|
|
2898
2857
|
// update homedir
|
|
2899
|
-
})
|
|
2858
|
+
}))
|
|
2859
|
+
|
|
2860
|
+
this.app.use((err, req, res, next) => {
|
|
2861
|
+
process.stdout.write("\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
2862
|
+
process.stdout.write("\r\n> ERROR\r\n")
|
|
2863
|
+
process.stdout.write(err.stack)
|
|
2864
|
+
process.stdout.write("\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n")
|
|
2865
|
+
res.status(500).render("500", {
|
|
2866
|
+
stack: err.stack
|
|
2867
|
+
})
|
|
2868
|
+
});
|
|
2869
|
+
|
|
2870
|
+
|
|
2900
2871
|
// install
|
|
2901
2872
|
this.server = httpserver.createServer(this.app);
|
|
2902
2873
|
this.socket = new Socket(this)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<style>
|
|
4
|
+
body {
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
margin: 0;
|
|
8
|
+
background: royalblue;
|
|
9
|
+
color: white;
|
|
10
|
+
padding: 50px;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
font-family: sans-serif;
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
}
|
|
15
|
+
h1 {
|
|
16
|
+
font-size: 40px;
|
|
17
|
+
text-transform: uppercase;
|
|
18
|
+
}
|
|
19
|
+
pre {
|
|
20
|
+
width: 100%;
|
|
21
|
+
}
|
|
22
|
+
footer {
|
|
23
|
+
border-left: 4px solid white;
|
|
24
|
+
padding: 10px 20px;
|
|
25
|
+
margin-top: 50px;
|
|
26
|
+
}
|
|
27
|
+
footer ol {
|
|
28
|
+
padding-inline-start: 20px;
|
|
29
|
+
margin: 0;
|
|
30
|
+
padding-top: 10px;
|
|
31
|
+
}
|
|
32
|
+
footer a {
|
|
33
|
+
color: white;
|
|
34
|
+
font-weight: bold;
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<h1>Error</h1>
|
|
40
|
+
<pre><%=stack%></pre>
|
|
41
|
+
<footer>
|
|
42
|
+
<div>You may want to try:</div>
|
|
43
|
+
<ol>
|
|
44
|
+
<li>Update to the latest version of Pinokio: <a href="https://program.pinokio.computer/#/?id=install" target="_blank">https://program.pinokio.computer/#/?id=install</a></li>
|
|
45
|
+
<li>Try troubleshooting: <a href="/?mode=settings#troubleshoot">Troubleshoot</a></li>
|
|
46
|
+
<li>Ask in community Discord: <a href="https://discord.gg/TQdNwadtE4" target="_blank">Discord</a></li>
|
|
47
|
+
</ol>
|
|
48
|
+
</footer>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
package/server/views/index.ejs
CHANGED
|
@@ -154,7 +154,7 @@ body.dark .browser-options-row {
|
|
|
154
154
|
<nav class='error-message'>
|
|
155
155
|
<div><%=error%></div>
|
|
156
156
|
<div class='flexible'></div>
|
|
157
|
-
<a class='btn' target="_blank" href="https://
|
|
157
|
+
<a class='btn' target="_blank" href="https://program.pinokio.computer/#/?id=install">Download</a>
|
|
158
158
|
</nav>
|
|
159
159
|
<% } %>
|
|
160
160
|
<!--
|