本次提交包含两批改动(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 全部通过。
88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
/* zikai 共享前端工具:toast、复制、字节/时间格式化、fetch 封装。
|
||
Basic Auth 同源时浏览器自动带缓存的凭据,无需额外处理;fetch 默认 same-origin。 */
|
||
(function (global) {
|
||
"use strict";
|
||
|
||
function el(tag, attrs, ...children) {
|
||
const node = document.createElement(tag);
|
||
if (attrs) {
|
||
for (const [k, v] of Object.entries(attrs)) {
|
||
if (k === "class") node.className = v;
|
||
else if (k === "dataset") Object.assign(node.dataset, v);
|
||
else if (k.startsWith("on") && typeof v === "function")
|
||
node.addEventListener(k.slice(2).toLowerCase(), v);
|
||
else if (v !== null && v !== undefined) node.setAttribute(k, v);
|
||
}
|
||
}
|
||
for (const c of children) {
|
||
if (c == null || c === false) continue;
|
||
node.appendChild(typeof c === "string" ? document.createTextNode(c) : c);
|
||
}
|
||
return node;
|
||
}
|
||
|
||
let toastTimer = null;
|
||
function toast(msg, kind) {
|
||
let node = document.querySelector(".toast");
|
||
if (!node) {
|
||
node = el("div", { class: "toast" });
|
||
document.body.appendChild(node);
|
||
}
|
||
node.textContent = msg;
|
||
node.className = "toast show" + (kind ? " " + kind : "");
|
||
clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(() => (node.className = "toast"), 2200);
|
||
}
|
||
|
||
async function copyText(text) {
|
||
try {
|
||
await navigator.clipboard.writeText(text);
|
||
return true;
|
||
} catch {
|
||
// 降级:临时 textarea
|
||
const ta = document.createElement("textarea");
|
||
ta.value = text;
|
||
ta.style.position = "fixed";
|
||
ta.style.opacity = "0";
|
||
document.body.appendChild(ta);
|
||
ta.select();
|
||
let ok = false;
|
||
try { ok = document.execCommand("copy"); } catch {}
|
||
document.body.removeChild(ta);
|
||
return ok;
|
||
}
|
||
}
|
||
|
||
function fmtBytes(n) {
|
||
if (n == null) return "-";
|
||
const x = Number(n);
|
||
if (!isFinite(x)) return "-";
|
||
for (const unit of ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]) {
|
||
if (Math.abs(x) < 1024 || unit === "PiB")
|
||
return unit === "B" ? `${x} B` : `${x.toFixed(1)} ${unit}`;
|
||
n = x / 1024;
|
||
}
|
||
return `${n.toFixed(1)} PiB`;
|
||
}
|
||
|
||
function fmtTime(s) {
|
||
if (!s) return "-";
|
||
const d = new Date(s);
|
||
if (isNaN(d.getTime())) return s;
|
||
const p = (n) => String(n).padStart(2, "0");
|
||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
||
}
|
||
|
||
async function api(path, opts) {
|
||
const res = await fetch(path, opts);
|
||
if (res.status === 401) {
|
||
// 触发浏览器 Basic Auth 弹窗(同源 reload 即可带上凭据)
|
||
toast("需要登录");
|
||
throw new Error("UNAUTHORIZED");
|
||
}
|
||
return res;
|
||
}
|
||
|
||
global.ZK = { el, toast, copyText, fmtBytes, fmtTime, api };
|
||
})(window);
|