show zip packaging progress on download

This commit is contained in:
2026-05-03 01:43:52 +08:00
parent a795aa13bf
commit 022828095b
2 changed files with 149 additions and 18 deletions

View File

@@ -508,7 +508,7 @@ def get_job(job_id):
return dict(job) if job else None
def start_job(kind, worker, owner=None, params=None):
def start_job(kind, worker, owner=None, params=None, remember_user_task=True):
job_id = uuid.uuid4().hex[:12]
owner = normalized_username(owner)
with JOBS_LOCK:
@@ -526,7 +526,8 @@ def start_job(kind, worker, owner=None, params=None):
"updatedAt": time.strftime("%Y-%m-%d %H:%M:%S"),
}
persist_jobs_locked()
set_user_task(owner, kind, job_id)
if remember_user_task:
set_user_task(owner, kind, job_id)
def run():
try:
@@ -573,6 +574,15 @@ def serialize_outputs(output_paths, preview_paths):
}
def file_metadata(file_path):
file_path = Path(file_path).resolve()
return {
"path": str(file_path),
"name": file_path.name,
"size": file_path.stat().st_size,
}
def prepare_deformation_zip(job_id, target):
job = get_job(job_id)
if not job:
@@ -712,6 +722,33 @@ class Handler(BaseHTTPRequestHandler):
self.send_json(make_preview(body["inputDir"], body.get("angleDegrees", 12)))
return
if parsed.path == "/api/deformation/package":
source_job_id = body["jobId"]
target = body.get("target", "all")
username = normalized_username(body.get("username"))
def worker(job_id):
label = "四状态总 ZIP" if target == "all" else "本状态 DICOM ZIP"
set_job(job_id, message=f"正在打包{label}...", progress=10)
zip_path = prepare_deformation_zip(source_job_id, target)
set_job(job_id, message="打包完成,准备下载...", progress=95)
return {"file": file_metadata(zip_path)}
self.send_json(
start_job(
"zip",
worker,
owner=username,
params={
"sourceJobId": source_job_id,
"target": target,
},
remember_user_task=False,
),
status=202,
)
return
if parsed.path == "/api/deformation":
input_dir = body["inputDir"]
angle_degrees = float(body.get("angleDegrees", 12))