|
@@ -1,6 +1,6 @@
|
|
|
from typing import Any, List, Optional
|
|
|
from datetime import datetime
|
|
|
-from fastapi import APIRouter, Body, Depends, HTTPException, Form, status, Response
|
|
|
+from fastapi import APIRouter, Body, Depends, HTTPException, Form, status, Response, BackgroundTasks
|
|
|
from fastapi.encoders import jsonable_encoder
|
|
|
from pydantic.networks import EmailStr, HttpUrl
|
|
|
from sqlalchemy.orm import Session
|
|
@@ -93,6 +93,7 @@ punctuation = r"[.,!?;:。 、!?,;:]"
|
|
|
@router.post('/gen-zip')
|
|
|
def generate_zip(
|
|
|
*,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
current_user: models.User = Depends(deps.get_current_active_user),
|
|
|
model:Optional[str],
|
|
|
texts:List[str]):
|
|
@@ -129,5 +130,6 @@ def generate_zip(
|
|
|
def remove_zip():
|
|
|
if os.path.exists(f'{output_dir}/{dir.name}.zip'):
|
|
|
os.remove(f'{output_dir}/{dir.name}.zip')
|
|
|
- return FileResponse(f'{output_dir}/{dir.name}.zip', background=remove_zip)
|
|
|
+ background_tasks.add_task(remove_zip)
|
|
|
+ return FileResponse(f'{output_dir}/{dir.name}.zip', media_type="application/zip")
|
|
|
|