README: 服务端完整文档; LICENSE: MIT
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 edgevoid
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,84 @@
|
||||
# 7z-encrypt-server 文件安全传输服务端
|
||||
|
||||
7z-encrypt 文件安全传输系统的服务端。**零知识 + 零合并**:只存密文卷、不持密钥、不解密、不合并。
|
||||
|
||||
```
|
||||
客户端上传密文卷 → 服务端只存卷 → 客户端逐卷下载 → 本地解密
|
||||
服务端手里永远只有密文: 没有密钥, 没有明文, 连文件名都是加密的
|
||||
```
|
||||
|
||||
## 特性
|
||||
|
||||
- **零知识**: 服务端无密钥不解密, 存储的全是密文卷, 管理员也看不到内容
|
||||
- **零合并**: complete 只校验卷齐 + 目录 move 入库, 秒回 (6 卷实测 1.1 秒), 服务端零 CPU 合并
|
||||
- **元数据零知识**: 文件名是客户端加密后的 URL-safe base64 (`enc:` 前缀), 服务端只见密文
|
||||
- **Bearer token 认证**: 无/错 token 一律 401
|
||||
- **卷级校验**: 每卷 SHA-256 校验, 坏卷 409 拒绝
|
||||
- **断点续传**: GET /chunks 查已收卷, 客户端只补传缺失卷
|
||||
- **空间配额**: 已用/配额/剩余/百分比
|
||||
- **文件管理**: ls / 逐卷下载 / 删除
|
||||
- **业务日志**: 所有端点事件 + 客户端 IP
|
||||
- **轻量**: FastAPI + SQLite, PRoot 容器 (手机 ZeroTermux) 都能跑
|
||||
|
||||
## 快速部署
|
||||
|
||||
```bash
|
||||
pip install fastapi uvicorn cryptography tqdm
|
||||
SZ_TOKEN=你的token python3 main.py # 默认 0.0.0.0:8000
|
||||
```
|
||||
|
||||
### 环境变量
|
||||
|
||||
| 变量 | 默认 | 说明 |
|
||||
|---|---|---|
|
||||
| SZ_TOKEN | sz-dev-token-change-me | 认证 token (必须设置, 与客户端一致) |
|
||||
| SZ_QUOTA | 10GB | 空间配额 |
|
||||
| SZ_DB_PATH | data/app.db | SQLite 路径 |
|
||||
| SZ_STORAGE_ROOT | data/storage | 密文卷存储目录 |
|
||||
| SZ_TMP_ROOT | data/tmp | 上传临时目录 |
|
||||
| SZ_HOST / SZ_PORT | 0.0.0.0 / 8000 | 监听地址 |
|
||||
|
||||
## API
|
||||
|
||||
```
|
||||
POST /api/transfer/init 建任务 {transfer_id}
|
||||
PUT /api/transfer/{id}/chunk/{n} 上传单卷密文 409 = 坏卷
|
||||
GET /api/transfer/{id}/chunks 已收卷列表 断点续传
|
||||
POST /api/transfer/{id}/complete 卷齐入库(秒回) {file_id}
|
||||
GET /api/files 文件列表 文件名是加密的
|
||||
GET /api/files/{id}/chunk/{n} 下载单卷密文 X-Enc-Params 头带解密参数
|
||||
DELETE /api/files/{id} 删除文件
|
||||
GET /api/quota 空间配额
|
||||
全部端点需 Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
## 日志与自愈
|
||||
|
||||
```
|
||||
/tmp/sz-server.log 业务日志 ([业务] 动作 IP 参数) + uvicorn 访问日志
|
||||
/tmp/sz-watchdog.log 看门狗日志
|
||||
tail -f /tmp/sz-server.log # 实时看
|
||||
```
|
||||
|
||||
- **start.sh**: 幂等拉起服务 + 看门狗 (已在跑则跳过), 容器重启自动恢复
|
||||
- **watchdog.sh**: 30 秒检查一次服务进程, 挂了自动拉起 (flock 防重复)
|
||||
- 容器唤醒钩子: `~/.bashrc` 末尾 `[ -f /root/server/start.sh ] && /root/server/start.sh`
|
||||
|
||||
## 存储结构
|
||||
|
||||
```
|
||||
data/
|
||||
├─ app.db SQLite (transfers / files / chunks)
|
||||
├─ storage/日期/任务ID/ 密文卷目录 (chunk_0001..N, 不合并)
|
||||
└─ tmp/任务ID/ 上传中的卷 (complete 后 move 入 storage)
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
.venv/bin/pytest -q # 9 项: 认证/全链路/坏卷/幂等/清洗/配额/删除
|
||||
```
|
||||
|
||||
## 协议
|
||||
|
||||
MIT License, Copyright (c) 2026 edgevoid
|
||||
Reference in New Issue
Block a user