Allow getting uploads as non-chunked
This commit is contained in:
parent
16c84189c3
commit
a1dad5d71d
|
@ -136,27 +136,35 @@ defmodule WikiWeb.PageController do
|
||||||
redirect(conn, to: Routes.page_path(conn, :edit, page.id))
|
redirect(conn, to: Routes.page_path(conn, :edit, page.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_upload(conn, _params) do
|
def get_upload(conn, params) do
|
||||||
upload = conn.assigns.upload
|
upload = conn.assigns.upload
|
||||||
key = get_session(conn, :content_encryption_key)
|
key = get_session(conn, :content_encryption_key)
|
||||||
key = Base.decode16!(key, case: :lower)
|
key = Base.decode16!(key, case: :lower)
|
||||||
|
|
||||||
conn =
|
if Map.get(params, "oneshot") do
|
||||||
|
data = Upload.decrypt_content(upload, key)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("content-type", upload.content_type)
|
|> put_resp_header("content-type", upload.content_type)
|
||||||
|> send_chunked(200)
|
|> send_resp(200, data)
|
||||||
|
else
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_resp_header("content-type", upload.content_type)
|
||||||
|
|> send_chunked(200)
|
||||||
|
|
||||||
upload
|
upload
|
||||||
|> Upload.decrypt_stream(key)
|
|> Upload.decrypt_stream(key)
|
||||||
|> Enum.reduce_while(conn, fn decrypted_chunk, conn ->
|
|> Enum.reduce_while(conn, fn decrypted_chunk, conn ->
|
||||||
case chunk(conn, decrypted_chunk) do
|
case chunk(conn, decrypted_chunk) do
|
||||||
{:ok, conn} ->
|
{:ok, conn} ->
|
||||||
{:cont, conn}
|
{:cont, conn}
|
||||||
|
|
||||||
{:error, :closed} ->
|
{:error, :closed} ->
|
||||||
{:halt, {:halt, conn}}
|
{:halt, {:halt, conn}}
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_upload(conn, _params) do
|
def delete_upload(conn, _params) do
|
||||||
|
|
Loading…
Reference in New Issue