Add backend failure handling with :ok | :error so the uploader can handle it.

defaulting to :ok, since that's the currently level of error handling.
This commit is contained in:
Thurloat 2018-08-29 22:07:28 -03:00
commit af01f0196a
6 changed files with 14 additions and 25 deletions

View file

@ -17,7 +17,7 @@ defmodule Pleroma.Uploaders.Local do
File.cp!(tmpfile, result_file)
end
url_path
{:ok, url_path}
end
def upload_path do

View file

@ -19,6 +19,6 @@ defmodule Pleroma.Uploaders.S3 do
])
|> ExAws.request()
"#{public_endpoint}/#{bucket}/#{s3_name}"
{:ok, "#{public_endpoint}/#{bucket}/#{s3_name}"}
end
end

View file

@ -11,20 +11,18 @@ defmodule Pleroma.Uploaders.Swift.Client do
end
def upload_file(filename, body, content_type) do
object_url = Keyword.fetch!(@settings, :object_url)
token = Pleroma.Uploaders.Swift.Keystone.get_token()
case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do
{:ok, %HTTPoison.Response{status_code: 201}} ->
# lgtm
""
{:ok, "#{object_url}/#{filename}"}
{:ok, %HTTPoison.Response{status_code: 401}} ->
# bad token
""
{:error, "Unauthorized, Bad Token"}
{:error, _} ->
# bad news
""
{:error, "Swift Upload Error"}
end
end
end

View file

@ -1,15 +1,10 @@
defmodule Pleroma.Uploaders.Swift do
@behaviour Pleroma.Uploaders.Uploader
@settings Application.get_env(:pleroma, Pleroma.Uploaders.Swift)
def put_file(name, uuid, tmp_path, content_type, _should_dedupe) do
{:ok, file_data} = File.read(tmp_path)
remote_name = "#{uuid}/#{name}"
Pleroma.Uploaders.Swift.Client.upload_file(remote_name, file_data, content_type)
object_url = Keyword.fetch!(@settings, :object_url)
"#{object_url}/#{remote_name}"
end
end

View file

@ -14,13 +14,5 @@ defmodule Pleroma.Uploaders.Uploader do
file :: File.t(),
content_type :: String.t(),
should_dedupe :: Boolean.t()
) :: String.t()
@callback put_file(
name :: String.t(),
uuid :: String.t(),
image_data :: String.t(),
content_type :: String.t(),
should_dedupe :: String.t()
) :: String.t()
) :: {:ok, String.t()} | {:error, String.t()}
end