aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/uploaders/swift/swift.ex
blob: 4f45255f127145a4c0de6ae03c7d20db45849844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
defmodule Pleroma.Uploaders.Swift.Client do
  use HTTPoison.Base

  @settings Application.get_env(:pleroma, Pleroma.Uploaders.Swift)

  def process_url(url) do
    Enum.join(
      [Keyword.fetch!(@settings, :storage_url), url],
      "/"
    )
  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
      {:ok, %HTTPoison.Response{status_code: 201}} ->
        # lgtm
        ""

      {:ok, %HTTPoison.Response{status_code: 401}} ->
        # bad token
        ""

      {:error, _} ->
        # bad news
        ""
    end
  end
end