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:
parent
c0f8e9a93c
commit
c63d878396
|
|
@ -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(_){}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue