nonebot-plugin-shiro-web-console 0.1.13__tar.gz → 0.1.14__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.13
3
+ Version: 0.1.14
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
@@ -58,3 +58,15 @@ pip install nonebot-plugin-shiro-web-console
58
58
  ```env
59
59
  web_console_password=your_password # 设置固定登录密码
60
60
  ```
61
+
62
+ ## 更新日志
63
+
64
+ ### v0.1.14
65
+ - **新增**:完整运行日志记录功能,支持在网页端直接下载。
66
+ - **优化**:添加插件商店操作锁,解决多插件同时更新导致的冲突问题。
67
+ - **优化**:改进插件版本获取逻辑,准确对比版本号并过滤非更新项。
68
+ - **优化**:优化移动端适配及部分 UI 交互。
69
+
70
+ ## 许可证
71
+
72
+ MIT
@@ -27,3 +27,15 @@ pip install nonebot-plugin-shiro-web-console
27
27
  ```env
28
28
  web_console_password=your_password # 设置固定登录密码
29
29
  ```
30
+
31
+ ## 更新日志
32
+
33
+ ### v0.1.14
34
+ - **新增**:完整运行日志记录功能,支持在网页端直接下载。
35
+ - **优化**:添加插件商店操作锁,解决多插件同时更新导致的冲突问题。
36
+ - **优化**:改进插件版本获取逻辑,准确对比版本号并过滤非更新项。
37
+ - **优化**:优化移动端适配及部分 UI 交互。
38
+
39
+ ## 许可证
40
+
41
+ MIT
@@ -767,84 +767,90 @@ if app:
767
767
 
768
768
  @app.post("/web_console/api/store/action", dependencies=[Depends(check_auth)])
769
769
  async def store_action(request: Request):
770
- data = await request.json()
771
- action = data.get("action") # install, update, uninstall
772
- plugin_name = data.get("plugin")
770
+ # 尝试获取锁,如果已被占用则立即返回错误,或等待
771
+ # 这里选择等待,确保操作按顺序执行
772
+ if store_lock.locked():
773
+ logger.warning("插件操作正在进行中,请求已排队...")
773
774
 
774
- if not action or not plugin_name:
775
- return {"error": "参数错误"}
775
+ async with store_lock:
776
+ data = await request.json()
777
+ action = data.get("action") # install, update, uninstall
778
+ plugin_name = data.get("plugin")
776
779
 
777
- if not re.match(r'^[a-zA-Z0-9_-]+$', plugin_name):
778
- return {"error": "非法插件名称"}
779
-
780
- # 执行命令
781
- import asyncio
782
- import sys
783
-
784
- # 构建命令
785
- cmd = []
786
- # 尝试定位 nb 命令
787
- import shutil
788
- nb_path = shutil.which("nb")
789
-
790
- if not nb_path:
791
- # 如果系统 PATH 中找不到,再尝试在 Python 脚本目录下找
792
- script_dir = os.path.dirname(sys.executable)
793
- possible_nb = os.path.join(script_dir, "nb.exe" if sys.platform == "win32" else "nb")
794
- if os.path.exists(possible_nb):
795
- nb_path = possible_nb
796
- else:
797
- nb_path = "nb" # 最后的保底,尝试直接运行 nb
798
-
799
- # 获取项目根目录 (通常是当前工作目录)
800
- root_dir = Path.cwd()
780
+ if not action or not plugin_name:
781
+ return {"error": "参数错误"}
782
+
783
+ if not re.match(r'^[a-zA-Z0-9_-]+$', plugin_name):
784
+ return {"error": "非法插件名称"}
801
785
 
802
- if action == "install":
803
- cmd = [nb_path, "plugin", "install", plugin_name]
804
- elif action == "update":
805
- cmd = [nb_path, "plugin", "update", plugin_name]
806
- elif action == "uninstall":
807
- cmd = [nb_path, "plugin", "uninstall", plugin_name]
808
- else:
809
- return {"error": "无效操作"}
786
+ # 执行命令
787
+ import asyncio
788
+ import sys
810
789
 
811
- logger.info(f"开始执行插件操作: {' '.join(cmd)} (工作目录: {root_dir})")
812
-
813
- try:
814
- process = await asyncio.create_subprocess_exec(
815
- *cmd,
816
- stdout=asyncio.subprocess.PIPE,
817
- stderr=asyncio.subprocess.PIPE,
818
- cwd=str(root_dir)
819
- )
820
-
821
- stdout_bytes, stderr_bytes = await process.communicate()
790
+ # 构建命令
791
+ cmd = []
792
+ # 尝试定位 nb 命令
793
+ import shutil
794
+ nb_path = shutil.which("nb")
822
795
 
823
- def safe_decode(data: bytes) -> str:
824
- if not data:
825
- return ""
826
- for encoding in ["utf-8", "gbk", "cp936"]:
827
- try:
828
- return data.decode(encoding).strip()
829
- except UnicodeDecodeError:
830
- continue
831
- return data.decode("utf-8", errors="replace").strip()
796
+ if not nb_path:
797
+ # 如果系统 PATH 中找不到,再尝试在 Python 脚本目录下找
798
+ script_dir = os.path.dirname(sys.executable)
799
+ possible_nb = os.path.join(script_dir, "nb.exe" if sys.platform == "win32" else "nb")
800
+ if os.path.exists(possible_nb):
801
+ nb_path = possible_nb
802
+ else:
803
+ nb_path = "nb" # 最后的保底,尝试直接运行 nb
832
804
 
833
- stdout = safe_decode(stdout_bytes)
834
- stderr = safe_decode(stderr_bytes)
835
-
836
- if process.returncode == 0:
837
- msg = f"插件 {plugin_name} {action} 成功"
838
- logger.info(msg)
839
- return {"msg": msg, "output": stdout}
805
+ # 获取项目根目录 (通常是当前工作目录)
806
+ root_dir = Path.cwd()
807
+
808
+ if action == "install":
809
+ cmd = [nb_path, "plugin", "install", plugin_name]
810
+ elif action == "update":
811
+ cmd = [nb_path, "plugin", "update", plugin_name]
812
+ elif action == "uninstall":
813
+ cmd = [nb_path, "plugin", "uninstall", plugin_name]
840
814
  else:
841
- error_msg = stderr or stdout
842
- logger.error(f"插件操作失败: {error_msg}")
843
- return {"error": error_msg}
815
+ return {"error": "无效操作"}
844
816
 
845
- except Exception as e:
846
- logger.error(f"执行插件命令时发生异常: {e}")
847
- return {"error": str(e)}
817
+ logger.info(f"开始执行插件操作: {' '.join(cmd)} (工作目录: {root_dir})")
818
+
819
+ try:
820
+ process = await asyncio.create_subprocess_exec(
821
+ *cmd,
822
+ stdout=asyncio.subprocess.PIPE,
823
+ stderr=asyncio.subprocess.PIPE,
824
+ cwd=str(root_dir)
825
+ )
826
+
827
+ stdout_bytes, stderr_bytes = await process.communicate()
828
+
829
+ def safe_decode(data: bytes) -> str:
830
+ if not data:
831
+ return ""
832
+ for encoding in ["utf-8", "gbk", "cp936"]:
833
+ try:
834
+ return data.decode(encoding).strip()
835
+ except UnicodeDecodeError:
836
+ continue
837
+ return data.decode("utf-8", errors="replace").strip()
838
+
839
+ stdout = safe_decode(stdout_bytes)
840
+ stderr = safe_decode(stderr_bytes)
841
+
842
+ if process.returncode == 0:
843
+ msg = f"插件 {plugin_name} {action} 成功"
844
+ logger.info(msg)
845
+ return {"msg": msg, "output": stdout}
846
+ else:
847
+ error_msg = stderr or stdout
848
+ logger.error(f"插件操作失败: {error_msg}")
849
+ return {"error": error_msg}
850
+
851
+ except Exception as e:
852
+ logger.error(f"执行插件命令时发生异常: {e}")
853
+ return {"error": str(e)}
848
854
 
849
855
  @app.post("/web_console/api/plugins/{plugin_id}/config", dependencies=[Depends(check_auth)])
850
856
  async def update_plugin_config(plugin_id: str, new_config: dict):
@@ -554,6 +554,7 @@
554
554
  <div style="font-weight: bold; font-size: 1.2em;">NoneBot 日志</div>
555
555
  <div style="display: flex; gap: 10px;">
556
556
  <button onclick="fetchLogs()" style="padding: 5px 12px; background: var(--primary-color); color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em;">刷新</button>
557
+ <button id="btn-download-log" onclick="downloadFullLog()" style="padding: 5px 12px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em;" title="下载完整运行日志">下载日志</button>
557
558
  <button onclick="document.getElementById('log-viewer').innerHTML = ''" style="padding: 5px 12px; background: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em;">清屏</button>
558
559
  </div>
559
560
  </div>
@@ -1697,6 +1698,36 @@
1697
1698
  sendBtn.onclick = sendMessage;
1698
1699
  msgInput.onkeypress = (e) => { if (e.key === 'Enter') sendMessage(); };
1699
1700
 
1701
+ // 下载完整日志
1702
+ async function downloadFullLog() {
1703
+ const btn = document.getElementById('btn-download-log');
1704
+ const originalText = btn.textContent;
1705
+ btn.textContent = '下载中...';
1706
+ btn.disabled = true;
1707
+ try {
1708
+ const res = await authorizedFetch('/web_console/api/logs/download');
1709
+ if (res.status === 404) {
1710
+ alert('暂无完整日志记录');
1711
+ return;
1712
+ }
1713
+ if (!res.ok) throw new Error('下载失败');
1714
+ const blob = await res.blob();
1715
+ const url = window.URL.createObjectURL(blob);
1716
+ const a = document.createElement('a');
1717
+ a.href = url;
1718
+ a.download = `nonebot_full_${new Date().toISOString().slice(0,10)}.log`;
1719
+ document.body.appendChild(a);
1720
+ a.click();
1721
+ window.URL.revokeObjectURL(url);
1722
+ document.body.removeChild(a);
1723
+ } catch (e) {
1724
+ alert('下载日志失败: ' + e.message);
1725
+ } finally {
1726
+ btn.textContent = originalText;
1727
+ btn.disabled = false;
1728
+ }
1729
+ }
1730
+
1700
1731
  // 初始化
1701
1732
  fetchChats();
1702
1733
  initWS();
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-shiro-web-console"
3
- version = "0.1.13"
3
+ version = "0.1.14"
4
4
  description = "一个用于 NoneBot2 的网页控制台插件,支持通过浏览器查看日志和发送消息"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"