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 全部通过。
This commit is contained in:
@@ -1,13 +1,37 @@
|
||||
"""请求 / 响应的 Pydantic DTO。"""
|
||||
|
||||
from .chunk import (
|
||||
ChunkUploadResponse,
|
||||
CreateSessionRequest,
|
||||
CreateSessionResponse,
|
||||
SessionStatusResponse,
|
||||
)
|
||||
from .file import FileListResponse, FileUploadResponse, UploadedFileOut
|
||||
from .system import DiskUsage, MemoryUsage, SystemStatus
|
||||
from .tunnel import TunnelStatusResponse
|
||||
from .whiteboard import (
|
||||
Stroke,
|
||||
StrokeOp,
|
||||
WhiteboardListItem,
|
||||
WhiteboardListResponse,
|
||||
WhiteboardOut,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"ChunkUploadResponse",
|
||||
"CreateSessionRequest",
|
||||
"CreateSessionResponse",
|
||||
"DiskUsage",
|
||||
"FileListResponse",
|
||||
"FileUploadResponse",
|
||||
"MemoryUsage",
|
||||
"SessionStatusResponse",
|
||||
"Stroke",
|
||||
"StrokeOp",
|
||||
"SystemStatus",
|
||||
"TunnelStatusResponse",
|
||||
"UploadedFileOut",
|
||||
"WhiteboardListItem",
|
||||
"WhiteboardListResponse",
|
||||
"WhiteboardOut",
|
||||
]
|
||||
|
||||
43
app/schemas/chunk.py
Normal file
43
app/schemas/chunk.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""分片上传接口 DTO。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CreateSessionRequest(BaseModel):
|
||||
"""创建一个分片上传会话。"""
|
||||
|
||||
filename: str = Field(..., description="客户端原始文件名")
|
||||
size_bytes: int = Field(..., ge=0, description="文件总字节数")
|
||||
chunk_size: int = Field(..., gt=0, description="分片大小(字节)")
|
||||
total_chunks: int = Field(..., gt=0, description="分片总数")
|
||||
|
||||
|
||||
class CreateSessionResponse(BaseModel):
|
||||
upload_id: str = Field(..., description="服务端生成的会话标识,后续接口都需要它")
|
||||
filename: str
|
||||
size_bytes: int
|
||||
chunk_size: int
|
||||
total_chunks: int
|
||||
|
||||
|
||||
class SessionStatusResponse(BaseModel):
|
||||
"""会话状态:前端据此决定还需补传哪些分片(断点续传)。"""
|
||||
|
||||
upload_id: str
|
||||
filename: str
|
||||
size_bytes: int
|
||||
chunk_size: int
|
||||
total_chunks: int
|
||||
uploaded_chunks: list[int] = Field(..., description="已上传的分片下标集合")
|
||||
completed: bool = Field(..., description="是否已完成拼接入库")
|
||||
file_id: int | None = Field(None, description="completed=true 时指向 UploadedFile.id")
|
||||
|
||||
|
||||
class ChunkUploadResponse(BaseModel):
|
||||
"""单个分片上传成功的回执。"""
|
||||
|
||||
upload_id: str
|
||||
index: int
|
||||
uploaded_chunks: list[int]
|
||||
@@ -28,19 +28,11 @@ class FileUploadResponse(BaseModel):
|
||||
sha256: str
|
||||
storage_path: str
|
||||
uploaded_at: datetime
|
||||
deduplicated: bool = Field(
|
||||
False, description="true=服务端已有同 sha256 文件,直接返回旧行,未重复落盘"
|
||||
)
|
||||
|
||||
|
||||
class FileListResponse(BaseModel):
|
||||
total: int
|
||||
items: list[UploadedFileOut]
|
||||
|
||||
|
||||
class SftpRegisterRequest(BaseModel):
|
||||
"""登记一个通过 SFTP 上传到 ``incoming/`` 下的文件。"""
|
||||
|
||||
filename: str = Field(
|
||||
...,
|
||||
description="文件在 SFTP chroot 下的相对路径,必须落在 incoming/ 之下,例如 incoming/abc.bin",
|
||||
)
|
||||
original_filename: str = Field(..., description="客户端原始文件名")
|
||||
uploaded_by: str = Field(default="sftp", description="登记者标识,写入 uploaded_by 字段")
|
||||
|
||||
19
app/schemas/tunnel.py
Normal file
19
app/schemas/tunnel.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""反向隧道接口 DTO。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class TunnelStatusResponse(BaseModel):
|
||||
"""隧道的当前状态(查 /api/userPort/{userName} 前可用于探测)。"""
|
||||
|
||||
user_name: str
|
||||
local_port: int
|
||||
tunnel_port: int
|
||||
started_at: datetime
|
||||
status: str
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
53
app/schemas/whiteboard.py
Normal file
53
app/schemas/whiteboard.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""白板接口 DTO。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Stroke(BaseModel):
|
||||
"""一条笔画:点序列 + 样式。结构宽松(Any)以兼容前端扩展字段。"""
|
||||
|
||||
points: list[list[float]] = Field(default_factory=list, description="[[x,y],...]")
|
||||
color: str = Field(default="#1565c0", description="笔画颜色")
|
||||
width: float = Field(default=3, description="笔画宽度")
|
||||
|
||||
|
||||
class WhiteboardOut(BaseModel):
|
||||
"""白板完整内容(GET /whiteboard/{id} 与 WS init 帧)。"""
|
||||
|
||||
board_id: str
|
||||
strokes: list[Any] = Field(default_factory=list, description="笔画数组")
|
||||
stroke_count: int = Field(0, description="累计修改次数")
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class WhiteboardListItem(BaseModel):
|
||||
"""管理页列表项。"""
|
||||
|
||||
board_id: str
|
||||
stroke_count: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class WhiteboardListResponse(BaseModel):
|
||||
"""管理页列表响应。"""
|
||||
|
||||
total: int
|
||||
items: list[WhiteboardListItem]
|
||||
|
||||
|
||||
class StrokeOp(BaseModel):
|
||||
"""WS 笔画操作(type=stroke 时携带)。"""
|
||||
|
||||
type: str = Field(..., description="add / clear")
|
||||
stroke: dict[str, Any] | None = Field(None, description="type=add 时携带的笔画对象")
|
||||
Reference in New Issue
Block a user