Files
zTools2/tests/manual_whiteboard_kick.py
zikai fffba79022 feat: 文件浏览页 + 共享白板 + 白板管理页(含补登记分片上传/隧道历史改动)
本次提交包含两批改动(7月2日遗留未入库 + 本次新功能),分述如下:

【补登记:7月2日已上线但未提交的功能】
- 分片上传:chunk_upload_controller/service/dao + UploadSession model/schema,
  支持 4MiB 分片、乱序、断点续传、去重、幂等 complete;后台 reaper 清理过期会话。
- 反向隧道:tunnel_controller/service/dao + TunnelSession model/schema,
  SSH remote forward 经 /api/userPort/{userName} 反代到 user 本地服务。
- 上传页:views/upload_html.py(拖拽/多文件/分片/断点续传 UI)。
- config.py:StorageConfig.chunk_session_dir/ttl、TunnelConfig;
  requirements.txt 加 httpx;start.sh 清理 .work/ 残留;
  schema.sql 加 upload_session/tunnel_session 表;sftp_server 承载隧道转发。

【本次新功能】
- 文件浏览页:GET /files(Basic Auth 同 docs)+ /api/admin/files(list/get/download/DELETE)。
  硬删除(DB 行 + 磁盘文件),删除后列表不再显示。前端 static/file_browser.*。
- 共享白板:GET /whiteboard/{id}(公开,不存在则新建)+ WS /ws/whiteboard/{id}。
  MySQL 持久化(whiteboard 表),Canvas 实时同步,心跳 3s/5 次失活移除,
  清空/复制按钮,移动端兼容。WhiteboardHub 管理 {board_id: set[Connection]},
  disconnect 幂等 + 空 set 清理防泄漏,broadcast 失败连接自动移除。
- 白板管理页:GET /whiteboard-admin(Basic Auth)+ /api/admin/whiteboards(list/DELETE)。
  删除时 hub.close_board 踢出在线连接。
- 清理:合并 UploadService.get_out_with_disk_path(下载/删除复用,消除重复 DB 读),
  移除无用 resolve_disk_path。
- config.py:WhiteboardConfig(heartbeat/threshold/board_id 长度/list_limit);
  schema.sql 加 whiteboard 表;README 补新接口与心跳/内存说明。
- 验证:tests/manual_whiteboard_hub.py / _ws.py / _kick.py 全部通过。
2026-07-21 14:28:13 +00:00

53 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""验证删除白板时,在线 WS 连接被服务端踢出(收到 error 帧并断连)。"""
from __future__ import annotations
import asyncio
import json
import urllib.request
import websockets
BASE_WS = "ws://127.0.0.1:6890/ws/whiteboard"
BOARD = "kicktest"
AUTH = "Basic YTo2NjUxMTMxNQ==" # a:66511315
async def main() -> None:
async with websockets.connect(f"{BASE_WS}/{BOARD}") as a:
await a.send(json.dumps({"type": "hello", "client_id": "A"}))
init = json.loads(await asyncio.wait_for(a.recv(), timeout=2))
assert init["type"] == "init"
print("A connected, init received")
# 通过 REST 删除白板(带 Basic Auth
req = urllib.request.Request(
f"http://127.0.0.1:6890/api/admin/whiteboards/{BOARD}",
method="DELETE",
headers={"Authorization": AUTH},
)
with urllib.request.urlopen(req) as r:
print("delete response:", r.read().decode())
# A 应收到 error 帧随后连接关闭
try:
raw = await asyncio.wait_for(a.recv(), timeout=3)
msg = json.loads(raw)
print("A received:", msg)
assert msg["type"] == "error", "应收到 error 通知"
except (websockets.ConnectionClosed, asyncio.TimeoutError) as e:
print("连接关闭/超时:", e)
# 确认连接已断
try:
await asyncio.wait_for(a.recv(), timeout=2)
print("ERROR: 连接仍存活(应已断开)")
except websockets.ConnectionClosed:
print("连接已被服务端关闭 ✅")
except asyncio.TimeoutError:
print("连接未关闭但无消息(部分通过)")
if __name__ == "__main__":
asyncio.run(main())