From 4fd17217cbe03ad1e8f5da8e38ae946afd31d037 Mon Sep 17 00:00:00 2001 From: Victor Mylle Date: Wed, 1 Mar 2023 10:24:19 +0000 Subject: [PATCH] Added response caching --- backend/src/routers/signvideo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/routers/signvideo.py b/backend/src/routers/signvideo.py index 4c65e08..b78b828 100644 --- a/backend/src/routers/signvideo.py +++ b/backend/src/routers/signvideo.py @@ -92,8 +92,8 @@ async def sign_video_thumbnail( # extract the thumbnail from the video bytes = extract_thumbnail(f"{settings.DATA_PATH}/{sign_video.path}") - return StreamingResponse(io.BytesIO(bytes), media_type="image/png") - + # return the thumbnail and make it cacheable for 60 days + return StreamingResponse(io.BytesIO(bytes), media_type="image/jpeg", headers={"Cache-Control": "max-age=5184000"}) @router.get("/{video_id}/", status_code=status.HTTP_200_OK) async def sign_video( @@ -114,8 +114,8 @@ async def sign_video( if not sign_video: raise BaseException("Sign video not found") - # return the video - return FileResponse(f"{settings.DATA_PATH}/{sign_video.path}", media_type="video/mp4") + # return the video and make it cacheable for 60 days + return FileResponse(f"{settings.DATA_PATH}/{sign_video.path}", media_type="video/mp4", headers={"Cache-Control": "max-age=5184000"}) class SignVideoUpdate(BaseModel):