api: 下载响应头 X-Chunk-Count (卷数); db: get_file 带 chunk_count

This commit is contained in:
lou
2026-08-10 01:24:18 +08:00
parent fc522afbaf
commit 3c4e683210
2 changed files with 7 additions and 3 deletions
+4 -1
View File
@@ -75,7 +75,10 @@ async def download_file(file_id: str):
return JSONResponse(status_code=404, content={"error": f"存储文件缺失: {path}"})
# 解密参数: 任务 init 时存的 enc {alg, key_id, context}
enc_params = json.dumps(rec["enc_params"], ensure_ascii=False)
headers = {"X-Enc-Params": base64.b64encode(enc_params.encode()).decode()}
headers = {
"X-Enc-Params": base64.b64encode(enc_params.encode()).decode(),
"X-Chunk-Count": str(rec["chunk_count"]), # 客户端按卷粒度显示进度
}
return FileResponse(
path,
filename=rec["file_name"],
+3 -2
View File
@@ -196,10 +196,11 @@ class ServerDB:
return [dict(r) for r in rows]
def get_file(self, file_id: str) -> dict[str, Any] | None:
"""单文件记录 (下载端点, 含解密参数 enc_params)"""
"""单文件记录 (下载端点, 含解密参数 enc_params + 卷数)"""
with self._conn() as conn:
row = conn.execute(
"SELECT f.file_id, f.file_name, f.path, f.size, f.sha256, t.enc_params "
"SELECT f.file_id, f.file_name, f.path, f.size, f.sha256, "
"t.enc_params, t.chunk_count "
"FROM files f JOIN transfers t ON f.transfer_id = t.transfer_id "
"WHERE f.file_id = ?",
(file_id,),