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))
|
||||
end
|
||||
|
||||
def get_upload(conn, _params) do
|
||||
def get_upload(conn, params) do
|
||||
upload = conn.assigns.upload
|
||||
key = get_session(conn, :content_encryption_key)
|
||||
key = Base.decode16!(key, case: :lower)
|
||||
|
||||
conn =
|
||||
if Map.get(params, "oneshot") do
|
||||
data = Upload.decrypt_content(upload, key)
|
||||
|
||||
conn
|
||||
|> 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.decrypt_stream(key)
|
||||
|> Enum.reduce_while(conn, fn decrypted_chunk, conn ->
|
||||
case chunk(conn, decrypted_chunk) do
|
||||
{:ok, conn} ->
|
||||
{:cont, conn}
|
||||
upload
|
||||
|> Upload.decrypt_stream(key)
|
||||
|> Enum.reduce_while(conn, fn decrypted_chunk, conn ->
|
||||
case chunk(conn, decrypted_chunk) do
|
||||
{:ok, conn} ->
|
||||
{:cont, conn}
|
||||
|
||||
{:error, :closed} ->
|
||||
{:halt, {:halt, conn}}
|
||||
end
|
||||
end)
|
||||
{:error, :closed} ->
|
||||
{:halt, {:halt, conn}}
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_upload(conn, _params) do
|
||||
|
|
Loading…
Reference in New Issue