pinokiod 3.8.44 → 3.8.46

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/server/index.js CHANGED
@@ -90,7 +90,6 @@ class Server {
90
90
  return new Promise(r=>fs.access(s, fs.constants.F_OK, e => r(!e)))
91
91
  }
92
92
  async updateMeta(formData, app_path) {
93
- console.log("icon_dirty?", formData.icon_dirty)
94
93
  if (formData.icon_dirty) {
95
94
  // write icon file
96
95
  let icon_path = this.kernel.path("api", formData.new_path, formData.icon_path)
@@ -117,7 +116,6 @@ class Server {
117
116
  }
118
117
  async createMeta(formData) {
119
118
  let icon_path = this.kernel.path("api", formData.path, "icon.png")
120
- console.log({ icon_path })
121
119
  await fs.promises.writeFile(icon_path, formData.avatar)
122
120
 
123
121
  // write title/description to pinokio_meta.json
@@ -377,7 +375,6 @@ class Server {
377
375
 
378
376
  // profile + feed
379
377
  const repositoryPath = path.resolve(this.kernel.api.userdir, name)
380
- console.log({ repositoryPath })
381
378
 
382
379
  try {
383
380
  await git.resolveRef({ fs, dir: repositoryPath, ref: 'HEAD' });
@@ -558,7 +555,6 @@ class Server {
558
555
  })
559
556
  } else if (pathComponents.length === 0 && req.query.mode === "download") {
560
557
  let { requirements, install_required, requirements_pending, error } = await this.kernel.bin.check_bin()
561
- console.log({ requirements, install_required, requirements_pending })
562
558
 
563
559
  res.render("download", {
564
560
  error,
@@ -618,7 +614,6 @@ class Server {
618
614
  drive: path.resolve(this.kernel.homedir, "drive"),
619
615
  }
620
616
  }
621
- console.log({ configArray })
622
617
  res.render("settings", {
623
618
  platform,
624
619
  version: this.version,
@@ -923,7 +918,6 @@ class Server {
923
918
  let install_required = true
924
919
  if (!requirements_pending) {
925
920
  install_required = false
926
- console.time(">>>>>>>>>> 1")
927
921
  for(let i=0; i<requirements.length; i++) {
928
922
  let r = requirements[i]
929
923
 
@@ -937,7 +931,6 @@ class Server {
937
931
  }
938
932
  }
939
933
  }
940
- console.timeEnd(">>>>>>>>>> 1")
941
934
  }
942
935
 
943
936
  let error = null
@@ -1006,7 +999,6 @@ class Server {
1006
999
  if (platform === "win32") {
1007
1000
  p = p.replace(/\\/g, '\\\\')
1008
1001
  }
1009
- console.log({ pre_items })
1010
1002
  res.render("required_env_editor", {
1011
1003
  agent: this.agent,
1012
1004
  theme: this.theme,
@@ -1016,7 +1008,6 @@ class Server {
1016
1008
  })
1017
1009
  } else {
1018
1010
  let logpath = encodeURIComponent(Util.log_path(filepath, this.kernel))
1019
- console.log({ logpath })
1020
1011
  const result = {
1021
1012
  prev,
1022
1013
  error,
@@ -1108,7 +1099,6 @@ class Server {
1108
1099
  // look for README.md
1109
1100
 
1110
1101
  let config
1111
- console.log("f.files", f.files)
1112
1102
  for(let file of f.files) {
1113
1103
  if (file.name.toLowerCase() === "readme.md") {
1114
1104
  let p = path.resolve(filepath, file.name)
@@ -1300,13 +1290,11 @@ class Server {
1300
1290
 
1301
1291
  // check if there is a running process with this folder name
1302
1292
  let runningApps = new Set()
1303
- console.log("running", this.kernel.api.running)
1304
1293
  for(let key in this.kernel.api.running) {
1305
1294
  let p = this.kernel.path("api", items[i].name) + path.sep
1306
1295
  //let re = new RegExp(items[i].name)
1307
1296
  //if (re.test(key)) {
1308
1297
  //if (p === key) {
1309
- console.log({ key, p})
1310
1298
  if (key.includes(p)) {
1311
1299
  items[i].running = true
1312
1300
  items[i].index = index
@@ -1438,7 +1426,6 @@ class Server {
1438
1426
  }
1439
1427
  if (config.xterm) {
1440
1428
  this.xterm = config.xterm
1441
- console.log("this.xterm", this.xterm)
1442
1429
  }
1443
1430
  }
1444
1431
  }
@@ -1888,7 +1875,6 @@ class Server {
1888
1875
  }
1889
1876
  }
1890
1877
  async sudo_exec(message, homedir) {
1891
- console.log("sudo_exec", { message, homedir })
1892
1878
  // sudo-prompt uses TEMP
1893
1879
  // let TEMP = path.resolve(homedir, "cache", "TEMP")
1894
1880
  // await fs.promises.mkdir(TEMP, { recursive: true }).catch((e) => { })
@@ -2121,7 +2107,6 @@ class Server {
2121
2107
  NO_PROXY: config.NO_PROXY,
2122
2108
  }
2123
2109
  let fullpath = path.resolve(this.kernel.homedir, "ENVIRONMENT")
2124
- console.log({ updated })
2125
2110
  await Util.update_env(fullpath, updated)
2126
2111
  }
2127
2112
 
@@ -2130,17 +2115,13 @@ class Server {
2130
2115
  this.kernel.store.set("NO_PROXY", config.NO_PROXY)
2131
2116
  }
2132
2117
  async startLogging(homedir) {
2133
- console.log(">>>>>>> startLogging", homedir)
2134
2118
  if (!this.debug) {
2135
2119
  if (this.logInterval) {
2136
2120
  clearInterval(this.logInterval)
2137
2121
  }
2138
2122
  if (homedir) {
2139
- console.log({ homedir })
2140
2123
  let logsdir = path.resolve(homedir, "logs")
2141
- console.log({ logsdir })
2142
2124
  await fs.promises.mkdir(logsdir, { recursive: true }).catch((e) => { console.log(e) })
2143
- console.log("this.log", this.log)
2144
2125
  if (!this.log) {
2145
2126
  this.log = fs.createWriteStream(path.resolve(homedir, "logs/stdout.txt"))
2146
2127
  process.stdout.write = process.stderr.write = this.log.write.bind(this.log)
@@ -2174,13 +2155,11 @@ class Server {
2174
2155
  }
2175
2156
  }
2176
2157
  async start(options) {
2177
- console.time("SERVER START")
2178
2158
  this.debug = false
2179
2159
  if (options) {
2180
2160
  this.debug = options.debug
2181
2161
  this.browser = options.browser
2182
2162
  }
2183
- console.time(">>>> 1")
2184
2163
 
2185
2164
  if (this.listening) {
2186
2165
  // stop proxies
@@ -2207,24 +2186,18 @@ class Server {
2207
2186
  // } catch (e) {
2208
2187
  // }
2209
2188
  }
2210
- console.timeEnd(">>>> 1")
2211
2189
 
2212
2190
  // configure from kernel.store
2213
- console.time(">>>> 2")
2214
2191
  await this.syncConfig()
2215
- console.timeEnd(">>>> 2")
2216
2192
 
2217
- console.time(">>>> 3")
2218
2193
  try {
2219
2194
  let _home = this.kernel.store.get("home")
2220
- console.log({ _home })
2221
2195
  if (_home) {
2222
2196
  await this.startLogging(_home)
2223
2197
  }
2224
2198
  } catch (e) {
2225
2199
  console.log("start logging attempt", e)
2226
2200
  }
2227
- console.timeEnd(">>>> 3")
2228
2201
 
2229
2202
  // determine port if port is not passed in
2230
2203
 
@@ -2253,11 +2226,8 @@ class Server {
2253
2226
  // }
2254
2227
  }
2255
2228
 
2256
- console.log("available port", this.port)
2257
-
2258
2229
  let version = this.kernel.store.get("version")
2259
2230
  let home = this.kernel.store.get("home")
2260
- console.log({ home, version })
2261
2231
 
2262
2232
  let needInitHome = false
2263
2233
  if (home) {
@@ -2286,17 +2256,12 @@ class Server {
2286
2256
  }
2287
2257
  }
2288
2258
  // initialize kernel
2289
- console.time(">>>> 4 kernel.init")
2290
2259
  await this.kernel.init({ port: this.port})
2291
- console.timeEnd(">>>> 4 kernel.init")
2292
2260
 
2293
2261
 
2294
- console.time(">>>> 5 kernel.initHome")
2295
- console.log({ needInitHome })
2296
2262
  if (needInitHome) {
2297
2263
  await this.kernel.initHome()
2298
2264
  }
2299
- console.timeEnd(">>>> 5 kernel.initHome")
2300
2265
 
2301
2266
  if (this.kernel.homedir) {
2302
2267
  let ex = await this.kernel.exists(this.kernel.homedir, "ENVIRONMENT")
@@ -2422,7 +2387,6 @@ class Server {
2422
2387
  //let home = this.kernel.homedir
2423
2388
  //let home = this.kernel.store.get("home")
2424
2389
  this.app.get("/", ex(async (req, res) => {
2425
- console.log("Shells", this.kernel.shell.shells.length)
2426
2390
  if (req.query.mode !== "settings" && !home) {
2427
2391
  res.redirect("/?mode=settings")
2428
2392
  return
@@ -2549,7 +2513,6 @@ class Server {
2549
2513
  // if (pinokio2.icon) meta[folder].icon = pinokio2.icon
2550
2514
  // }
2551
2515
  }
2552
- console.log("META", { meta })
2553
2516
  await this.render(req, res, [], meta)
2554
2517
  // if (this.kernel.bin.all_installed) {
2555
2518
  // this.started = true
@@ -2659,31 +2622,40 @@ class Server {
2659
2622
  })
2660
2623
  }))
2661
2624
  this.app.get("/proxy", ex(async (req, res) => {
2662
- await this.kernel.caddy.update()
2625
+ await this.kernel.router.refresh()
2663
2626
  let list = await this.kernel.processes.refresh()
2664
- let current_lan_ip = this.kernel.peer.current_ip
2665
- console.log("this.kernel.caddy.mapping", this.kernel.caddy.mapping())
2666
2627
  list = list.map((item) => {
2667
2628
  return {
2668
2629
  //proxy: this.kernel.caddy.mapping[item.ip] || [],
2669
- proxy: this.kernel.caddy.mapping()[current_lan_ip][item.ip] || [],
2630
+ router: this.kernel.router.info()[this.kernel.peer.host][item.ip] || [],
2670
2631
  ...item
2671
2632
  }
2672
2633
  })
2673
- console.log("list", list)
2674
2634
 
2675
- let peers = this.kernel.peer.get()
2676
- peers = peers.map((x) => {
2677
- let account = this.kernel.peer.account(x)
2678
- let domain = `https://pinokio.${account}.localhost`
2679
- let proxy_page = `https://pinokio.${account}.localhost/proxy`
2680
- return {
2681
- ip: x,
2682
- account,
2683
- domain,
2684
- proxy_page
2685
- }
2686
- })
2635
+ let peers_info = await this.kernel.peer.refresh()
2636
+ let peers = []
2637
+ for(let host in peers_info) {
2638
+ let peer_info = peers_info[host]
2639
+ peers.push({
2640
+ host,
2641
+ name: peer_info.name,
2642
+ domain: `https://pinokio.${peer_info.name}.localhost`,
2643
+ router: `https://pinokio.${peer_info.name}.localhost/proxy`
2644
+ })
2645
+ }
2646
+
2647
+ // let peers = this.kernel.peer.get()
2648
+ // peers = peers.map((x) => {
2649
+ // let account = this.kernel.peer.account(x)
2650
+ // let domain = `https://pinokio.${account}.localhost`
2651
+ // let proxy_page = `https://pinokio.${account}.localhost/proxy`
2652
+ // return {
2653
+ // ip: x,
2654
+ // account,
2655
+ // domain,
2656
+ // proxy_page
2657
+ // }
2658
+ // })
2687
2659
 
2688
2660
  let live_proxies = this.kernel.api.proxies["/proxy"]
2689
2661
  if (!live_proxies) live_proxies = []
@@ -2745,23 +2717,20 @@ class Server {
2745
2717
  let pinokio2 = (await this.kernel.loader.load(p2)).resolved
2746
2718
  if (pinokio) {
2747
2719
  let cc = Object.assign({} , pinokio , pinokio2);
2748
- console.log({ pinokio, pinokio2, cc })
2749
2720
  cc.link = `/pinokio/browser/${folder}/browse#n1`,
2750
2721
  cc.icon = cc.icon ? `/api/${folder}/${cc.icon}?raw=true` : null
2751
2722
  cc.name = cc.title
2752
- console.log("after", { pinokio, pinokio2, cc })
2753
2723
  apps.push(cc)
2754
2724
  }
2755
2725
  }
2756
2726
 
2757
- console.log({ port_mapping: this.kernel.caddy.port_mapping, ip_mapping: this.kernel.caddy.ip_mapping, lan: this.kernel.caddy.local_network_mapping, ip: this.kernel.peer.current_ip })
2758
2727
  res.render("proxy", {
2759
2728
  ip: this.kernel.peer.current_ip,
2760
2729
  peers,
2761
2730
  list,
2762
- port_mapping: this.kernel.caddy.port_mapping,
2763
- ip_mapping: this.kernel.caddy.ip_mapping,
2764
- lan: this.kernel.caddy.local_network_mapping,
2731
+ // port_mapping: this.kernel.caddy.port_mapping,
2732
+ // ip_mapping: this.kernel.caddy.ip_mapping,
2733
+ lan: this.kernel.router.local_network_mapping,
2765
2734
  agent: this.agent,
2766
2735
  theme: this.theme,
2767
2736
  items: proxies,
@@ -2793,7 +2762,6 @@ class Server {
2793
2762
  this.app.post("/copy", ex(async (req, res) => {
2794
2763
  let src_path = path.resolve(this.kernel.api.userdir, req.body.src)
2795
2764
  let dest_path = path.resolve(this.kernel.api.userdir, req.body.dest)
2796
- console.log({ src_path, dest_path })
2797
2765
  try {
2798
2766
  await fs.promises.cp(src_path, dest_path, { recursive: true })
2799
2767
  res.json({
@@ -3130,7 +3098,6 @@ class Server {
3130
3098
  }
3131
3099
  }
3132
3100
  }
3133
- console.log({ cloudflare_links, local_links })
3134
3101
  res.render("share_editor", {
3135
3102
  cloudflare_links,
3136
3103
  local_links,
@@ -3290,14 +3257,12 @@ class Server {
3290
3257
  */
3291
3258
 
3292
3259
  }))
3293
- this.app.get("/pinokio/mem", ex((req, res) => {
3260
+ this.app.get("/pinokio/peer", ex((req, res) => {
3294
3261
  res.json({
3295
- homedir: this.kernel.homedir,
3296
- account: this.kernel.peer.current_account,
3297
- proxy: this.kernel.caddy.mapping(), // mapping: { IP => https_domain }
3298
- ports: this.kernel.caddy.port_mapping,
3299
- lan: this.kernel.caddy.local_network_mapping,
3300
- ips: this.kernel.caddy.ip_mapping,
3262
+ home: this.kernel.homedir,
3263
+ name: this.kernel.peer.name,
3264
+ host: this.kernel.peer.host,
3265
+ router: this.kernel.router.info(),
3301
3266
  memory: this.kernel.memory
3302
3267
  })
3303
3268
  }))
@@ -3921,7 +3886,6 @@ class Server {
3921
3886
  });
3922
3887
  })
3923
3888
  this.kernel.peer.start()
3924
- console.timeEnd("SERVER START")
3925
3889
 
3926
3890
 
3927
3891
  }
@@ -254,7 +254,6 @@ document.addEventListener("DOMContentLoaded", async () => {
254
254
  }
255
255
  } else if (packet.type === "input") {
256
256
  let params = packet.data
257
- console.log(">> input", { params })
258
257
  /*
259
258
  params := {
260
259
  title,
@@ -247,8 +247,8 @@ td:first-child, th:first-child {
247
247
  <div class='header-container'>
248
248
  <div class='header-label-sub'><i class="fa-solid fa-podcast"></i> Local Network</div>
249
249
  <% peers.forEach((item) => { %>
250
- <a target="_blank" href="<%=item.proxy_page%>" class='line align-top'>
251
- <h3 class='table-grid'><%=item.account%></h3>
250
+ <a target="_blank" href="<%=item.router%>" class='line align-top'>
251
+ <h3 class='table-grid'><%=item.name%></h3>
252
252
  </a>
253
253
  <% }) %>
254
254
  </div>
@@ -265,9 +265,9 @@ td:first-child, th:first-child {
265
265
  <tr>
266
266
  <td class='title'><%=item.name%></td>
267
267
  <td>
268
- <% item.proxy.forEach((ip) => { %>
268
+ <% item.router.forEach((domain) => { %>
269
269
  <div>
270
- <a target="_blank" href="https://<%=ip%>">https://<%=ip%></a>
270
+ <a target="_blank" href="https://<%=domain%>">https://<%=domain%></a>
271
271
  </div>
272
272
  <% }) %>
273
273
  </td>