fix qrcode zip downloads
This commit is contained in:
@@ -87,6 +87,21 @@ def _public_base_url() -> str:
|
||||
return settings.public_base_url.rstrip("/") or "http://127.0.0.1:8000"
|
||||
|
||||
|
||||
def qrcode_batch_zip_path(task: DeviceQrBatchTask) -> Path:
|
||||
return settings.upload_path / "qrcode_zips" / task.file_name
|
||||
|
||||
|
||||
def qrcode_batch_zip_exists(task: DeviceQrBatchTask) -> bool:
|
||||
return bool(task.file_name and qrcode_batch_zip_path(task).is_file())
|
||||
|
||||
|
||||
def _task_download_url(task: DeviceQrBatchTask, public_base_url: str) -> str:
|
||||
return (
|
||||
f"{public_base_url.rstrip('/')}/api/devices/molds/qrcode/batch/tasks/"
|
||||
f"{task.id}/download"
|
||||
)
|
||||
|
||||
|
||||
def _task_file_name(items: list[dict]) -> str:
|
||||
fingerprint = hashlib.sha1(
|
||||
"|".join(
|
||||
@@ -153,9 +168,9 @@ def qrcode_batch_task_out(task: DeviceQrBatchTask, public_base_url: str | None =
|
||||
progress_percent = 0.0
|
||||
else:
|
||||
progress_percent = round(min(100, completed_count / item_count * 100), 1)
|
||||
zip_url = task.zip_url
|
||||
if public_base_url and task.file_name:
|
||||
zip_url = f"{public_base_url.rstrip('/')}/uploads/qrcode_zips/{quote(task.file_name, safe='')}"
|
||||
zip_url = None
|
||||
if task.status == QRCODE_TASK_STATUS_COMPLETED and qrcode_batch_zip_exists(task):
|
||||
zip_url = _task_download_url(task, public_base_url) if public_base_url else task.zip_url
|
||||
return DeviceQrBatchTaskOut(
|
||||
id=task.id,
|
||||
file_name=task.file_name,
|
||||
|
||||
Reference in New Issue
Block a user