Added response caching

This commit is contained in:
2023-03-01 10:24:19 +00:00
parent 013063f0be
commit 4fd17217cb

View File

@@ -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):