[#2497] Added Cache-Control response header for media proxy preview endpoint.

This commit is contained in:
Ivan Tashkinov 2020-08-31 13:08:50 +03:00
parent 3737f38432
commit 0a839d51a7
1 changed files with 10 additions and 6 deletions

View File

@ -107,8 +107,7 @@ defp handle_png_preview(%{params: params} = conn, url) do
}
) do
conn
|> put_resp_header("content-type", "image/png")
|> put_resp_header("content-disposition", "inline; filename=\"preview.png\"")
|> put_preview_response_headers()
|> send_resp(200, thumbnail_binary)
else
_ ->
@ -126,8 +125,7 @@ defp handle_jpeg_preview(%{params: params} = conn, url) do
%{max_width: thumbnail_max_width, max_height: thumbnail_max_height, quality: quality}
) do
conn
|> put_resp_header("content-type", "image/jpeg")
|> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
|> put_preview_response_headers()
|> send_resp(200, thumbnail_binary)
else
_ ->
@ -139,8 +137,7 @@ defp handle_video_preview(conn, url) do
with {:ok, thumbnail_binary} <-
MediaHelper.video_framegrab(url) do
conn
|> put_resp_header("content-type", "image/jpeg")
|> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
|> put_preview_response_headers()
|> send_resp(200, thumbnail_binary)
else
_ ->
@ -148,6 +145,13 @@ defp handle_video_preview(conn, url) do
end
end
defp put_preview_response_headers(conn) do
conn
|> put_resp_header("content-type", "image/jpeg")
|> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
|> put_resp_header("cache-control", "max-age=0, private, must-revalidate")
end
defp thumbnail_max_dimensions(params) do
config = Config.get([:media_preview_proxy], [])