mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-04 23:53:11 +00:00
5bb88fd174
Related to #85 Everything should now be configured at runtime, with the exception of the `Pleroma.HTML` scrubbers (the scrubbers used can be changed at runtime, but their configuration is compile-time) because it's building a module with a macro.
27 lines
756 B
Elixir
27 lines
756 B
Elixir
defmodule Pleroma.Uploaders.Swift.Client do
|
|
use HTTPoison.Base
|
|
|
|
def process_url(url) do
|
|
Enum.join(
|
|
[Pleroma.Config.get!([Pleroma.Uploaders.Swift, :storage_url]), url],
|
|
"/"
|
|
)
|
|
end
|
|
|
|
def upload_file(filename, body, content_type) do
|
|
object_url = Pleroma.Config.get!([Pleroma.Uploaders.Swift, :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}} ->
|
|
{:ok, "#{object_url}/#{filename}"}
|
|
|
|
{:ok, %HTTPoison.Response{status_code: 401}} ->
|
|
{:error, "Unauthorized, Bad Token"}
|
|
|
|
{:error, _} ->
|
|
{:error, "Swift Upload Error"}
|
|
end
|
|
end
|
|
end
|