1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-18 10:59:17 +00:00

[#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

View file

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