2018-08-29 03:32:24 +02:00
|
|
|
defmodule Pleroma.Uploaders.Swift.Client do
|
|
|
|
use HTTPoison.Base
|
|
|
|
|
|
|
|
def process_url(url) do
|
|
|
|
Enum.join(
|
2018-11-06 19:34:57 +01:00
|
|
|
[Pleroma.Config.get!([Pleroma.Uploaders.Swift, :storage_url]), url],
|
2018-08-29 03:32:24 +02:00
|
|
|
"/"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_file(filename, body, content_type) do
|
2018-11-06 19:34:57 +01:00
|
|
|
object_url = Pleroma.Config.get!([Pleroma.Uploaders.Swift, :object_url])
|
2018-08-29 03:32:24 +02:00
|
|
|
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}} ->
|
2018-08-30 03:07:28 +02:00
|
|
|
{:ok, "#{object_url}/#{filename}"}
|
2018-08-29 03:32:24 +02:00
|
|
|
|
|
|
|
{:ok, %HTTPoison.Response{status_code: 401}} ->
|
2018-08-30 03:07:28 +02:00
|
|
|
{:error, "Unauthorized, Bad Token"}
|
2018-08-29 03:32:24 +02:00
|
|
|
|
|
|
|
{:error, _} ->
|
2018-08-30 03:07:28 +02:00
|
|
|
{:error, "Swift Upload Error"}
|
2018-08-29 03:32:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|