Reorder fns

ex-snapshot
Marcin Kulik 7 years ago
parent 85823d8b83
commit 618cc93601

@ -68,20 +68,6 @@ defmodule Asciinema.Asciicasts do
end
end
defp do_create_asciicast(changeset, files) do
{_, result} = Repo.transaction(fn ->
case Repo.insert(changeset) do
{:ok, %Asciicast{} = asciicast} ->
Enum.each(files, fn {type, upload} -> save_file(asciicast, type, upload) end)
{:ok, asciicast}
otherwise ->
otherwise
end
end)
result
end
defp extract_attrs(%{"version" => 1} = attrs) do
attrs = %{version: attrs["version"],
duration: attrs["duration"],
@ -97,6 +83,20 @@ defmodule Asciinema.Asciicasts do
{:error, :unknown_format}
end
defp do_create_asciicast(changeset, files) do
{_, result} = Repo.transaction(fn ->
case Repo.insert(changeset) do
{:ok, %Asciicast{} = asciicast} ->
Enum.each(files, fn {type, upload} -> save_file(asciicast, type, upload) end)
{:ok, asciicast}
otherwise ->
otherwise
end
end)
result
end
defp save_file(asciicast, type, %{path: tmp_file_path, content_type: content_type}) do
file_store_path = Asciicast.file_store_path(asciicast, type)
:ok = FileStore.put_file(file_store_path, tmp_file_path, content_type)

Loading…
Cancel
Save