swift.ex (800B)
1 # Pleroma: A lightweight social networking server 2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> 3 # SPDX-License-Identifier: AGPL-3.0-only 4 5 defmodule Pleroma.Uploaders.Swift.Client do 6 use HTTPoison.Base 7 8 def process_url(url) do 9 Enum.join( 10 [Pleroma.Config.get!([Pleroma.Uploaders.Swift, :storage_url]), url], 11 "/" 12 ) 13 end 14 15 def upload_file(filename, body, content_type) do 16 token = Pleroma.Uploaders.Swift.Keystone.get_token() 17 18 case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do 19 {:ok, %Tesla.Env{status: 201}} -> 20 {:ok, {:file, filename}} 21 22 {:ok, %Tesla.Env{status: 401}} -> 23 {:error, "Unauthorized, Bad Token"} 24 25 {:error, _} -> 26 {:error, "Swift Upload Error"} 27 end 28 end 29 end