Added docker-compose file

This commit is contained in:
2023-02-20 13:39:44 +01:00
parent 163ae21b11
commit dfe86fc47f
2 changed files with 39 additions and 4 deletions

View File

@@ -1,8 +1,9 @@
import asyncio
import datetime
import os
import zipfile
from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, BackgroundTasks, Depends, status
from fastapi.responses import FileResponse
from fastapi_jwt_auth import AuthJWT
from pydantic import BaseModel
@@ -97,7 +98,7 @@ async def delete_sign(id: int, Authorize: AuthJWT = Depends(), session: AsyncSes
return {"message": "Sign deleted"}
@router.get("/download/all", status_code=status.HTTP_200_OK)
async def download_all(Authorize: AuthJWT = Depends(), session: AsyncSession = Depends(get_session)):
async def download_all(background_tasks: BackgroundTasks, Authorize: AuthJWT = Depends(), session: AsyncSession = Depends(get_session)):
Authorize.jwt_required()
user = Authorize.get_jwt_subject()
@@ -120,5 +121,12 @@ async def download_all(Authorize: AuthJWT = Depends(), session: AsyncSession = D
for path in paths:
zip_file.write(f"{settings.DATA_PATH}/{path}", os.path.basename(path))
# return the zip file and delete it after the request is done
return FileResponse(zip_path, media_type="application/zip", filename="signs.zip", delete_after_request=True)
background_tasks.add_task(delete_zip_file, zip_path)
# serve the zip file as the response
response = FileResponse(zip_path, media_type="application/zip", filename="signs.zip")
return response
# define a function to delete the zip file
async def delete_zip_file(zip_path):
os.remove(zip_path)