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:
@@ -152,5 +152,27 @@
|
||||
"framework.command.execute"
|
||||
],
|
||||
"timestamp": 26497.118727235
|
||||
},
|
||||
"d030c615": {
|
||||
"plugin_name": "example_plugin",
|
||||
"permissions": [
|
||||
"plugin.example.read",
|
||||
"plugin.example.write",
|
||||
"plugin.example.execute",
|
||||
"framework.event.subscribe",
|
||||
"framework.command.execute"
|
||||
],
|
||||
"timestamp": 26605.864670631
|
||||
},
|
||||
"fe466e0e": {
|
||||
"plugin_name": "sentinel",
|
||||
"permissions": [
|
||||
"plugin.sentinel.read",
|
||||
"plugin.sentinel.write",
|
||||
"plugin.network.access",
|
||||
"framework.event.subscribe",
|
||||
"framework.command.execute"
|
||||
],
|
||||
"timestamp": 26605.866739485
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ commands:
|
||||
permissions:
|
||||
- framework.command.test
|
||||
source: internal
|
||||
last_updated: 26497.09846161
|
||||
last_updated: 26605.852289433
|
||||
plugin_commands:
|
||||
example_plugin:
|
||||
echo: *id001
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
http_port: 4200
|
||||
last_updated: 26497.116694526
|
||||
last_updated: 26605.865204328
|
||||
plugin_routes:
|
||||
example_plugin:
|
||||
- methods:
|
||||
|
||||
@@ -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,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
||||
|
||||
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(){
|
||||
|
||||
Reference in New Issue
Block a user