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"
|
"framework.command.execute"
|
||||||
],
|
],
|
||||||
"timestamp": 26497.118727235
|
"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:
|
permissions:
|
||||||
- framework.command.test
|
- framework.command.test
|
||||||
source: internal
|
source: internal
|
||||||
last_updated: 26497.09846161
|
last_updated: 26605.852289433
|
||||||
plugin_commands:
|
plugin_commands:
|
||||||
example_plugin:
|
example_plugin:
|
||||||
echo: *id001
|
echo: *id001
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
http_port: 4200
|
http_port: 4200
|
||||||
last_updated: 26497.116694526
|
last_updated: 26605.865204328
|
||||||
plugin_routes:
|
plugin_routes:
|
||||||
example_plugin:
|
example_plugin:
|
||||||
- methods:
|
- methods:
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var sseConn = null;
|
var pollTimer = null;
|
||||||
var editingId = null;
|
var editingId = null;
|
||||||
|
|
||||||
function switchTab(t) {
|
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 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 esc(s) { return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
||||||
|
|
||||||
function connectSSE() {
|
function pollNodes() {
|
||||||
if (sseConn) { sseConn.close(); sseConn = null; }
|
fetch("/sentinel/api/nodes").then(function(r){return r.json()}).then(function(d){
|
||||||
sseConn = new EventSource("/plugin/sentinel/sse");
|
|
||||||
sseConn.addEventListener("nodes_update", function(e){
|
|
||||||
var d = JSON.parse(e.data);
|
|
||||||
if (d.nodes) renderNodes(d.nodes);
|
if (d.nodes) renderNodes(d.nodes);
|
||||||
});
|
}).catch(function(){});
|
||||||
sseConn.onerror = function(){ setTimeout(connectSSE, 5000); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("/sentinel/api/nodes").then(function(r){return r.json()}).then(function(d){
|
pollNodes();
|
||||||
if (d.nodes) renderNodes(d.nodes);
|
pollTimer = setInterval(pollNodes, 2000);
|
||||||
}).catch(function(){});
|
|
||||||
connectSSE();
|
|
||||||
|
|
||||||
// ═══ 节点管理 ═══
|
// ═══ 节点管理 ═══
|
||||||
function showAdd(){
|
function showAdd(){
|
||||||
|
|||||||
Reference in New Issue
Block a user