零知识: transfer 带 token + download 返回 enc_params + --decrypt 本地解密还原; config 加 server.token; 测试 62 项
This commit is contained in:
@@ -18,7 +18,7 @@ DEFAULT_CONFIG = Path(__file__).resolve().parent / "config" / "config.json"
|
||||
|
||||
# 默认值 (用户 config.json 逐层覆盖)
|
||||
DEFAULTS: dict[str, Any] = {
|
||||
"server": {"url": "", "timeout": 30, "max_retries": 3, "retry_delay": 1.0},
|
||||
"server": {"url": "", "token": "", "timeout": 30, "max_retries": 3, "retry_delay": 1.0},
|
||||
"crypto": {"key_id": "default_key", "keyring_path": "config/keyring.json"},
|
||||
"splitter": {"chunk_size_mb": 10},
|
||||
"state": {"db_path": "config/tasks.db", "cleanup_days": 7},
|
||||
@@ -95,6 +95,11 @@ class AppConfig:
|
||||
def retry_delay(self) -> float:
|
||||
return self.data["server"]["retry_delay"]
|
||||
|
||||
@property
|
||||
def token(self) -> str:
|
||||
"""服务端认证 token (Bearer)"""
|
||||
return self.data["server"]["token"]
|
||||
|
||||
@property
|
||||
def key_id(self) -> str:
|
||||
return self.data["crypto"]["key_id"]
|
||||
@@ -144,6 +149,7 @@ def main() -> int:
|
||||
ap.add_argument("--init", action="store_true", help="生成默认 config.json 模板")
|
||||
ap.add_argument("--path", default=str(DEFAULT_CONFIG), help="配置文件路径")
|
||||
ap.add_argument("--set-server", metavar="URL", help="更新 server.url 并保存")
|
||||
ap.add_argument("--set-token", metavar="TOKEN", help="更新 server.token 并保存")
|
||||
args = ap.parse_args()
|
||||
|
||||
if args.init:
|
||||
@@ -157,6 +163,7 @@ def main() -> int:
|
||||
{
|
||||
"server": {
|
||||
"url": "http://127.0.0.1:8000",
|
||||
"token": "",
|
||||
"timeout": 30,
|
||||
"max_retries": 3,
|
||||
"retry_delay": 1.0,
|
||||
@@ -188,13 +195,27 @@ def main() -> int:
|
||||
print(f"[config] server.url -> {args.set_server} ({path})")
|
||||
return 0
|
||||
|
||||
if args.set_token:
|
||||
path = Path(args.path)
|
||||
if not path.exists():
|
||||
print(f"[错误] 配置文件不存在: {path}, 先 --init 生成")
|
||||
return 1
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
data.setdefault("server", {})["token"] = args.set_token
|
||||
path.write_text(
|
||||
json.dumps(data, indent=2, ensure_ascii=False) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"[config] server.token 已更新 ({path})")
|
||||
return 0
|
||||
|
||||
try:
|
||||
cfg = AppConfig(args.path)
|
||||
except (ConfigError, json.JSONDecodeError) as e:
|
||||
print(f"[错误] 配置无效: {e}")
|
||||
return 1
|
||||
print(f"[config] 已加载: {cfg.config_path}")
|
||||
print(f" server: {cfg.server_url} (timeout={cfg.timeout}, retries={cfg.max_retries})")
|
||||
print(f" server: {cfg.server_url} (token={'已设置' if cfg.token else '未设置'}, timeout={cfg.timeout}, retries={cfg.max_retries})")
|
||||
print(f" crypto: key_id={cfg.key_id}, keyring={cfg.keyring_path}")
|
||||
print(f" splitter: 卷大小 {cfg.data['splitter']['chunk_size_mb']} MB")
|
||||
print(f" state: db={cfg.db_path}, 清理保留 {cfg.cleanup_days} 天")
|
||||
|
||||
Reference in New Issue
Block a user