pinokiod 7.1.66 → 7.1.68

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.1.66",
3
+ "version": "7.1.68",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -5480,43 +5480,53 @@ class Server {
5480
5480
  return list
5481
5481
  }
5482
5482
  async check_router_up() {
5483
- // check if caddy is runnign properly
5484
- // try https://pinokio.localhost
5485
- // if it works, proceed
5486
- // if not, redirect
5487
- let https_running = false
5483
+ let response
5484
+ let config
5488
5485
  try {
5489
5486
  let res = await axios.get(`http://127.0.0.1:2019/config/`, {
5490
5487
  timeout: 2000
5491
5488
  })
5492
- let test = /pinokio\.localhost/.test(JSON.stringify(res.data))
5493
- if (test) {
5494
- https_running = true
5495
- }
5489
+ config = res.data
5496
5490
  } catch (e) {
5497
- // console.log(e)
5498
- }
5499
- // console.log({ https_running })
5500
- if (!https_running) {
5501
- return { error: "pinokio.host not yet available" }
5491
+ response = {
5492
+ stage: "caddy_admin_unavailable",
5493
+ error: "caddy admin unavailable",
5494
+ detail: e && e.message ? e.message : String(e)
5495
+ }
5502
5496
  }
5503
-
5504
-
5505
- // check if pinokio.localhost router is running
5506
- let router_running = false
5507
- let router = this.kernel.router.published()
5508
- for(let ip in router) {
5509
- let domains = router[ip]
5510
- if (domains.includes("pinokio.localhost")) {
5511
- router_running = true
5512
- break
5497
+ if (!response) {
5498
+ if (config === null || typeof config === "undefined") {
5499
+ response = {
5500
+ stage: "caddy_config_empty",
5501
+ error: "caddy config not yet loaded"
5502
+ }
5503
+ } else if (!/pinokio\.localhost/.test(JSON.stringify(config))) {
5504
+ response = {
5505
+ stage: "caddy_route_missing",
5506
+ error: "pinokio.localhost missing from caddy config"
5507
+ }
5508
+ } else {
5509
+ let router_running = false
5510
+ let router = this.kernel.router.published()
5511
+ for (let ip in router) {
5512
+ let domains = router[ip]
5513
+ if (domains.includes("pinokio.localhost")) {
5514
+ router_running = true
5515
+ break
5516
+ }
5517
+ }
5518
+ if (!router_running) {
5519
+ response = {
5520
+ stage: "pinokio_router_missing",
5521
+ error: "pinokio.localhost not yet published by Pinokio router"
5522
+ }
5523
+ }
5513
5524
  }
5514
5525
  }
5515
- if (!router_running) {
5516
- return { error: "pinokio.localhost not yet available" }
5526
+ if (!response) {
5527
+ response = { success: true, stage: "ready" }
5517
5528
  }
5518
-
5519
- return { success: true }
5529
+ return response
5520
5530
  }
5521
5531
  async start(options) {
5522
5532
  this.debug = false
@@ -11428,37 +11438,8 @@ class Server {
11428
11438
  return
11429
11439
  }
11430
11440
 
11431
- let https_running = false
11432
- try {
11433
- let res = await axios.get(`http://127.0.0.1:2019/config/`, {
11434
- timeout: 2000
11435
- })
11436
- let test = /pinokio\.localhost/.test(JSON.stringify(res.data))
11437
- if (test) {
11438
- https_running = true
11439
- }
11440
- } catch (e) {
11441
- console.log(e)
11442
- }
11443
- if (!https_running) {
11444
- // res.json({ error: "pinokio.host not yet available" })
11445
- res.redirect("/setup/connect?callback=/connect/" + req.params.provider)
11446
- return
11447
- }
11448
-
11449
-
11450
- // check if pinokio.localhost router is running
11451
- let router_running = false
11452
- let router = this.kernel.router.published()
11453
- for(let ip in router) {
11454
- let domains = router[ip]
11455
- if (domains.includes("pinokio.localhost")) {
11456
- router_running = true
11457
- break
11458
- }
11459
- }
11460
- if (!router_running) {
11461
- // res.json({ error: "pinokio.localhost not yet available" })
11441
+ const routerStatus = await this.check_router_up()
11442
+ if (!routerStatus.success) {
11462
11443
  res.redirect("/setup/connect?callback=/connect/" + req.params.provider)
11463
11444
  return
11464
11445
  }
@@ -15576,6 +15557,13 @@ class Server {
15576
15557
  server_ready: true,
15577
15558
  phase: this.getStartupStatus().phase === "idle" ? "ready" : this.getStartupStatus().phase
15578
15559
  })
15560
+ if (this.kernel && this.kernel.peer && this.kernel.peer.https_active) {
15561
+ this.kernel.refresh(true).then(() => {
15562
+ return this.check_router_up()
15563
+ }).catch((error) => {
15564
+ console.warn("[Pinokiod] initial secure router refresh failed", error && error.message ? error.message : error)
15565
+ })
15566
+ }
15579
15567
  resolve()
15580
15568
  });
15581
15569
  this.httpTerminator = createHttpTerminator({
@@ -49,11 +49,6 @@
49
49
  color-scheme: light;
50
50
  }
51
51
 
52
- body[data-page="connect"][data-agent="electron"] {
53
- padding-top: 26px;
54
- box-sizing: border-box;
55
- }
56
-
57
52
  @media (prefers-color-scheme: dark) {
58
53
  body[data-page="connect"] {
59
54
  --connect-body-bg: #010617;
@@ -558,10 +553,8 @@
558
553
  const name = "<%=name%>"
559
554
  const SECURE_CONNECT_POLL_INTERVAL = 2000
560
555
  const SECURE_CONNECT_TIMEOUT = 120000
561
- const SECURE_CONNECT_BROWSER_RETRY_DELAY = 1200
562
556
  let secureConnectPollTimer = null
563
557
  let secureConnectTimeoutHandle = null
564
- let secureConnectBrowserRetryHandle = null
565
558
 
566
559
  function generateRandomString(length) {
567
560
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -593,21 +586,6 @@
593
586
  .replace(/=/g, '');
594
587
  }
595
588
 
596
- async function openAuthInBrowser(authUrl) {
597
- const response = await fetch('/go', {
598
- method: 'POST',
599
- headers: { 'Content-Type': 'application/json' },
600
- body: JSON.stringify({ url: authUrl })
601
- });
602
- if (!response.ok) {
603
- throw new Error(`Browser launch failed with status ${response.status}`);
604
- }
605
- const payload = await response.json().catch(() => ({}));
606
- if (payload && payload.error) {
607
- throw new Error(payload.error);
608
- }
609
- }
610
-
611
589
  // OAuth functions
612
590
  async function login() {
613
591
  try {
@@ -641,24 +619,10 @@
641
619
  startSecureConnectPolling();
642
620
  setStatus(`Continue the ${name} login in your browser.`, 'warning');
643
621
  try {
644
- if (secureConnectBrowserRetryHandle) {
645
- clearTimeout(secureConnectBrowserRetryHandle);
646
- secureConnectBrowserRetryHandle = null;
647
- }
648
- await openAuthInBrowser(authUrl);
649
- secureConnectBrowserRetryHandle = setTimeout(async () => {
650
- secureConnectBrowserRetryHandle = null;
651
- try {
652
- const token = await ensureValidToken();
653
- if (!token && document.visibilityState === 'visible' && document.hasFocus()) {
654
- await openAuthInBrowser(authUrl);
655
- }
656
- } catch (retryError) {
657
- console.warn('Retry browser launch failed:', retryError);
658
- }
659
- }, SECURE_CONNECT_BROWSER_RETRY_DELAY);
622
+ window.open(authUrl, '_blank', 'browser');
660
623
  } catch (openError) {
661
- stopSecureConnectPolling(`Could not open the browser automatically. Please open ${authUrl} manually.`, 'error');
624
+ hideLoader();
625
+ setStatus(`Could not open the browser. Please open ${authUrl} manually.`, 'error');
662
626
  return;
663
627
  }
664
628
  return;
@@ -684,10 +648,6 @@
684
648
  clearTimeout(secureConnectTimeoutHandle);
685
649
  secureConnectTimeoutHandle = null;
686
650
  }
687
- if (secureConnectBrowserRetryHandle) {
688
- clearTimeout(secureConnectBrowserRetryHandle);
689
- secureConnectBrowserRetryHandle = null;
690
- }
691
651
  if (message) {
692
652
  hideLoader();
693
653
  setStatus(message, type);
@@ -866,15 +826,12 @@
866
826
 
867
827
  function startHttpConnect() {
868
828
  stopConnectPolling()
869
- showLoader('Connecting... Complete the login in the secure window.', {
829
+ showLoader(`Connecting... Complete the login in the ${CONNECT_AGENT === 'electron' ? 'browser' : 'secure window'}.`, {
870
830
  cancellable: true,
871
831
  onCancel: () => stopConnectPolling('Connection cancelled.', 'warning')
872
832
  })
873
833
  setStatus('Waiting for connection...', 'warning')
874
- const secureWindow = window.open(SECURE_CONNECT_URL, '_blank')
875
- if (!secureWindow) {
876
- setStatus('Could not open the secure window. Please allow pop-ups or open https://pinokio.localhost/connect/<%=name%> manually.', 'error')
877
- }
834
+ window.open(SECURE_CONNECT_URL, '_blank', 'browser')
878
835
  pollConnectStatus()
879
836
  connectPollTimer = setInterval(pollConnectStatus, CONNECT_POLL_INTERVAL)
880
837
  connectTimeoutHandle = setTimeout(() => {
@@ -243,6 +243,12 @@ document.addEventListener("DOMContentLoaded", async () => {
243
243
  const waitRoot = document.querySelector(".requirements .content")
244
244
  const waitLabel = document.querySelector(".requirements .content .loading span")
245
245
  const WAIT_TIMEOUT_MS = 120000
246
+ const ROUTER_STAGE_MESSAGES = {
247
+ caddy_admin_unavailable: "Restarting Pinokio... (waiting for Caddy)",
248
+ caddy_config_empty: "Restarting Pinokio... (publishing secure router)",
249
+ caddy_route_missing: "Restarting Pinokio... (loading pinokio.localhost)",
250
+ pinokio_router_missing: "Restarting Pinokio... (waiting for Pinokio router)"
251
+ }
246
252
  const setWaitLabel = (message) => {
247
253
  if (waitLabel) {
248
254
  waitLabel.textContent = message
@@ -314,10 +320,13 @@ document.addEventListener("DOMContentLoaded", async () => {
314
320
  lastKnownError = startupStatus.error
315
321
  }
316
322
  if (startupStatus && startupStatus.phase) {
317
- lastKnownPhase = startupStatus.phase
318
- const phaseMessage = startupStatus.phase === "ready"
323
+ lastKnownPhase = (routerStatus && routerStatus.stage) || startupStatus.phase
324
+ const routerStageMessage = routerStatus && routerStatus.stage
325
+ ? ROUTER_STAGE_MESSAGES[routerStatus.stage]
326
+ : null
327
+ const phaseMessage = routerStageMessage || (startupStatus.phase === "ready"
319
328
  ? "Secure router is almost ready..."
320
- : `Restarting Pinokio... (${startupStatus.phase.replace(/_/g, " ")})`
329
+ : `Restarting Pinokio... (${startupStatus.phase.replace(/_/g, " ")})`)
321
330
  setWaitLabel(phaseMessage)
322
331
  }
323
332