fix: Sentinel 改用前端轮询替代 SSE (解决 EventSource 认证问题)

SSE 跨 panel_auth 认证层不可靠 → 改用 setInterval 每 2s fetch /sentinel/api/nodes

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
qinglong
2026-06-13 18:00:34 +08:00
parent a21e092207
commit c416b04798
4 changed files with 30 additions and 14 deletions
+6 -12
View File
@@ -66,7 +66,7 @@
</style>
<script>
var sseConn = null;
var pollTimer = null;
var editingId = null;
function switchTab(t) {
@@ -116,20 +116,14 @@
function fmtSpeed(bps) { return bps<1024?bps.toFixed(0)+'B/s':(bps<1048576?(bps/1024).toFixed(0)+'K/s':(bps/1048576).toFixed(1)+'M/s'); }
function esc(s) { return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function connectSSE() {
if (sseConn) { sseConn.close(); sseConn = null; }
sseConn = new EventSource("/plugin/sentinel/sse");
sseConn.addEventListener("nodes_update", function(e){
var d = JSON.parse(e.data);
function pollNodes() {
fetch("/sentinel/api/nodes").then(function(r){return r.json()}).then(function(d){
if (d.nodes) renderNodes(d.nodes);
});
sseConn.onerror = function(){ setTimeout(connectSSE, 5000); };
}).catch(function(){});
}
fetch("/sentinel/api/nodes").then(function(r){return r.json()}).then(function(d){
if (d.nodes) renderNodes(d.nodes);
}).catch(function(){});
connectSSE();
pollNodes();
pollTimer = setInterval(pollNodes, 2000);
// ═══ 节点管理 ═══
function showAdd(){