nonebot-plugin-shiro-web-console 0.1.9__tar.gz → 0.1.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nonebot-plugin-shiro-web-console might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-shiro-web-console
3
- Version: 0.1.9
3
+ Version: 0.1.11
4
4
  Summary: 一个用于 NoneBot2 的网页控制台插件,支持通过浏览器查看日志和发送消息
5
5
  Project-URL: Homepage, https://github.com/luojisama/nonebot-plugin-shiro-web-console
6
6
  Project-URL: Bug Tracker, https://github.com/luojisama/nonebot-plugin-shiro-web-console/issues
@@ -35,7 +35,7 @@ __plugin_meta__ = PluginMetadata(
35
35
  supported_adapters={"~onebot.v11"},
36
36
  extra={
37
37
  "author": "luojisama",
38
- "version": "0.1.9",
38
+ "version": "0.1.11",
39
39
  "pypi_test": "nonebot-plugin-shiro-web-console",
40
40
  },
41
41
  )
@@ -709,12 +709,26 @@
709
709
  if (!confirm(`确定要${actionText}机器人吗?`)) return;
710
710
 
711
711
  try {
712
- const res = await authorizedFetch('/web_console/api/system/action', {
712
+ // 第一次请求(可能返回需要确认)
713
+ let res = await authorizedFetch('/web_console/api/system/action', {
713
714
  method: 'POST',
714
715
  body: JSON.stringify({ action })
715
716
  });
716
- const data = await res.json();
717
+ let data = await res.json();
717
718
 
719
+ // 如果后端返回需要确认
720
+ if (data.need_confirm) {
721
+ const confirmed = confirm('确定要执行此操作吗?');
722
+ if (!confirmed) return;
723
+
724
+ // 再次发送带确认的请求
725
+ res = await authorizedFetch('/web_console/api/system/action', {
726
+ method: 'POST',
727
+ body: JSON.stringify({ action, confirm: true })
728
+ });
729
+ data = await res.json();
730
+ }
731
+
718
732
  if (data.error) {
719
733
  // 使用更友好的错误显示方式
720
734
  const errorArea = document.createElement('div');
@@ -1307,6 +1321,8 @@
1307
1321
  }
1308
1322
  };
1309
1323
 
1324
+ let appInterval = null;
1325
+
1310
1326
  async function initApp() {
1311
1327
  initWS();
1312
1328
  await fetchChats();
@@ -1317,9 +1333,11 @@
1317
1333
 
1318
1334
  showPage('home');
1319
1335
  // 定时刷新状态
1320
- setInterval(() => {
1336
+ if (appInterval) clearInterval(appInterval);
1337
+ appInterval = setInterval(() => {
1321
1338
  if (document.getElementById('page-home').classList.contains('active')) fetchStatus();
1322
- if (document.getElementById('page-logs').classList.contains('active')) fetchLogs();
1339
+ // 日志已通过 WebSocket 推送,不再轮询,避免刷屏
1340
+ // if (document.getElementById('page-logs').classList.contains('active')) fetchLogs();
1323
1341
  }, 5000);
1324
1342
  }
1325
1343
 
@@ -1343,6 +1361,11 @@
1343
1361
 
1344
1362
  // 初始化 WebSocket
1345
1363
  function initWS() {
1364
+ if (ws) {
1365
+ ws.onclose = null; // 防止触发重连
1366
+ ws.close();
1367
+ }
1368
+
1346
1369
  const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
1347
1370
  // 添加 token 参数防止连接被服务端拒绝 (code 1008)
1348
1371
  const wsUrl = `${protocol}//${window.location.host}/web_console/ws?token=${authToken}`;
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-shiro-web-console"
3
- version = "0.1.9"
3
+ version = "0.1.11"
4
4
  description = "一个用于 NoneBot2 的网页控制台插件,支持通过浏览器查看日志和发送消息"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"