fix: dashboard fallback to ntfy when backend 404 and static missing

- frontend now tries 3 sources: backend /status -> static /dashboard-plugins/.../link.json -> https://ntfy.sh/kUIJK0H1ettQ4VkR/json?poll=1
- shows link from ntfy even when dashboard backend not mounted (no restart needed)
- bump v2.5.2
This commit is contained in:
6zev 2026-09-03 05:32:34 +00:00
parent c0f8e9a93c
commit c63d878396
3 changed files with 35 additions and 5 deletions

View File

@ -34,7 +34,7 @@
try { try {
const r = await fetchJSONAllowError("/api/plugins/sshx-link/status"); const r = await fetchJSONAllowError("/api/plugins/sshx-link/status");
if (r.detail && r.detail.includes("No such API endpoint")) { 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 { try {
const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" }); const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" });
if (staticRes.ok) { 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; } 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(_){} } 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"); 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; return;
} }
if (r.link) { setLink(r.link); setStatus("running"); setMsg(null); } if (r.link) { setLink(r.link); setStatus("running"); setMsg(null); }
else { else {
// also try static fallback even when backend says stopped (gateway may have created file)
try { try {
const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" }); const staticRes = await fetch("/dashboard-plugins/sshx-link/dist/link.json", { cache: "no-store" });
if (staticRes.ok) { if (staticRes.ok) {
@ -58,6 +73,21 @@
if (m) { setLink(m[0]); setStatus("running"); return; } if (m) { setLink(m[0]); setStatus("running"); return; }
} }
} catch(_){} } 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"); setLink(null); setStatus(r.status || "stopped");
} }
} catch(_){} } catch(_){}

View File

@ -3,7 +3,7 @@
"label": "sshx.io Terminal", "label": "sshx.io Terminal",
"description": "Auto-start sshx via systemd/nohup, pid starttime guard, gửi ntfy — dashboard ẩn", "description": "Auto-start sshx via systemd/nohup, pid starttime guard, gửi ntfy — dashboard ẩn",
"icon": "Terminal", "icon": "Terminal",
"version": "2.5.1", "version": "2.5.2",
"tab": { "tab": {
"path": "/sshx", "path": "/sshx",
"position": "end", "position": "end",

View File

@ -1,5 +1,5 @@
name: sshx-link 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 description: Auto-start sshx via nohup và gửi link về ntfy.sh/kUIJK0H1ettQ4VkR — dashboard ẩn
author: sisyphus author: sisyphus
provides_tools: provides_tools: