diff --git a/dashboard/dist/index.js b/dashboard/dist/index.js index 83f6e91..3527b5e 100644 --- a/dashboard/dist/index.js +++ b/dashboard/dist/index.js @@ -34,7 +34,7 @@ try { const r = await fetchJSONAllowError("/api/plugins/sshx-link/status"); if (r.detail && r.detail.includes("No such API endpoint")) { - // backend not mounted (needs restart) -> fallback to static file written by gateway nohup + // backend not mounted -> try static file, then ntfy try { const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" }); if (staticRes.ok) { @@ -43,13 +43,28 @@ if (m) { setLink(m[0]); setStatus("running"); setMsg("Link từ static file (gateway nohup) — backend chưa mount nhưng vẫn hiển thị được"); return; } } } catch(_){} + // fallback to ntfy.sh directly (gateway đã gửi) + try { + const ntfyRes = await fetch("https://ntfy.sh/kUIJK0H1ettQ4VkR/json?poll=1", { cache: "no-store" }); + if (ntfyRes.ok) { + const txt = await ntfyRes.text(); + const lines = txt.trim().split("\n"); + for (let i=lines.length-1; i>=0; i--) { + try { + const obj = JSON.parse(lines[i]); + const msg = obj.message || ""; + const m = msg.match(/https:\/\/sshx\.io\/s\/[A-Za-z0-9\-_]+(?:#[^\s"']*)?/); + if (m) { setLink(m[0]); setStatus("running"); setMsg("Link từ ntfy.sh/kUIJK0H1ettQ4VkR (gateway đã gửi) — backend chưa mount"); return; } + } catch(_){} + } + } + } catch(_){} setStatus("needs_restart"); - setMsg("Backend chưa mount (404) — Dashboard chưa restart sau update. Đang thử đọc /dashboard-plugins/sshx-link/dist/link.json (gateway đã tạo). Nếu vẫn không có, sẽ tự restart sau 1.5s."); + setMsg("Backend chưa mount (404) — Dashboard chưa restart sau update. Đang thử đọc static và ntfy. Nếu vẫn không có, sẽ tự restart sau 1.5s."); return; } if (r.link) { setLink(r.link); setStatus("running"); setMsg(null); } else { - // also try static fallback even when backend says stopped (gateway may have created file) try { const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" }); if (staticRes.ok) { @@ -58,6 +73,21 @@ if (m) { setLink(m[0]); setStatus("running"); return; } } } catch(_){} + // also try ntfy even when backend says stopped + try { + const ntfyRes = await fetch("https://ntfy.sh/kUIJK0H1ettQ4VkR/json?poll=1", { cache: "no-store" }); + if (ntfyRes.ok) { + const txt = await ntfyRes.text(); + const lines = txt.trim().split("\n"); + for (let i=lines.length-1; i>=0; i--) { + try { + const obj = JSON.parse(lines[i]); + const m = (obj.message||"").match(/https:\/\/sshx\.io\/s\/[A-Za-z0-9\-_]+(?:#[^\s"']*)?/); + if (m) { setLink(m[0]); setStatus("running"); return; } + } catch(_){} + } + } + } catch(_){} setLink(null); setStatus(r.status || "stopped"); } } catch(_){} diff --git a/dashboard/manifest.json b/dashboard/manifest.json index 1af77b8..e25a7c6 100644 --- a/dashboard/manifest.json +++ b/dashboard/manifest.json @@ -3,7 +3,7 @@ "label": "sshx.io Terminal", "description": "Auto-start sshx via systemd/nohup, pid starttime guard, gửi ntfy — dashboard ẩn", "icon": "Terminal", - "version": "2.5.1", + "version": "2.5.2", "tab": { "path": "/sshx", "position": "end", diff --git a/plugin.yaml b/plugin.yaml index f32165f..df8e46f 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: sshx-link -version: 2.5.1 +version: 2.5.2 description: Auto-start sshx via nohup và gửi link về ntfy.sh/kUIJK0H1ettQ4VkR — dashboard ẩn author: sisyphus provides_tools: