fix qrcode zip downloads
This commit is contained in:
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
from urllib.parse import quote, unquote, urlparse
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -28,6 +29,7 @@ from app.services.qrcode_batch_tasks import (
|
||||
QRCODE_TASK_STATUS_RUNNING,
|
||||
create_qrcode_batch_task,
|
||||
qrcode_batch_task_out,
|
||||
qrcode_batch_zip_path,
|
||||
)
|
||||
from app.services.wechat import WechatConfigError, create_device_qrcode
|
||||
|
||||
@@ -373,6 +375,25 @@ def _get_own_batch_task(db: Session, user: Personnel, task_id: int) -> DeviceQrB
|
||||
return task
|
||||
|
||||
|
||||
@router.get("/molds/qrcode/batch/tasks/{task_id}/download")
|
||||
def download_mold_process_qrcode_batch_task(
|
||||
task_id: int,
|
||||
user: Personnel = Depends(require_roles(Role.admin)),
|
||||
db: Session = Depends(get_db),
|
||||
) -> FileResponse:
|
||||
task = _get_own_batch_task(db, user, task_id)
|
||||
if task.status != QRCODE_TASK_STATUS_COMPLETED:
|
||||
raise HTTPException(status_code=409, detail="二维码ZIP任务还未完成")
|
||||
file_path = qrcode_batch_zip_path(task)
|
||||
if not file_path.is_file():
|
||||
raise HTTPException(status_code=404, detail="ZIP文件不存在或已过期,请重新生成")
|
||||
return FileResponse(
|
||||
path=file_path,
|
||||
media_type="application/zip",
|
||||
filename=task.file_name,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/molds/qrcode/batch/tasks/{task_id}/stop", response_model=DeviceQrBatchTaskOut)
|
||||
def stop_mold_process_qrcode_batch_task(
|
||||
task_id: int,
|
||||
|
||||
Reference in New Issue
Block a user