2018-12-23 13:04:54 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2018-12-31 08:41:47 -07:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:04:54 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-08-28 19:32:24 -06:00
|
|
|
defmodule Pleroma.Uploaders.Swift.Client do
|
|
|
|
use HTTPoison.Base
|
|
|
|
|
|
|
|
def process_url(url) do
|
|
|
|
Enum.join(
|
2018-11-06 11:34:57 -07:00
|
|
|
[Pleroma.Config.get!([Pleroma.Uploaders.Swift, :storage_url]), url],
|
2018-08-28 19:32:24 -06:00
|
|
|
"/"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_file(filename, body, content_type) do
|
|
|
|
token = Pleroma.Uploaders.Swift.Keystone.get_token()
|
|
|
|
|
|
|
|
case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do
|
2018-12-02 07:08:36 -07:00
|
|
|
{:ok, %Tesla.Env{status: 201}} ->
|
2018-11-23 09:40:45 -07:00
|
|
|
{:ok, {:file, filename}}
|
2018-08-28 19:32:24 -06:00
|
|
|
|
2018-12-02 07:08:36 -07:00
|
|
|
{:ok, %Tesla.Env{status: 401}} ->
|
2018-08-29 19:07:28 -06:00
|
|
|
{:error, "Unauthorized, Bad Token"}
|
2018-08-28 19:32:24 -06:00
|
|
|
|
|
|
|
{:error, _} ->
|
2018-08-29 19:07:28 -06:00
|
|
|
{:error, "Swift Upload Error"}
|
2018-08-28 19:32:24 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|