better config reading
[akkoma] / lib / pleroma / uploaders / mdii.ex
1 defmodule Pleroma.Uploaders.MDII do
2 alias Pleroma.Config
3
4 @behaviour Pleroma.Uploaders.Uploader
5
6 @httpoison Application.get_env(:pleroma, :httpoison)
7
8 def put_file(name, uuid, path, content_type, _should_dedupe) do
9 cgi = Pleroma.Config.get([Pleroma.Uploaders.MDII, :cgi])
10 files = Pleroma.Config.get([Pleroma.Uploaders.MDII, :files])
11
12 {:ok, file_data} = File.read(path)
13
14 File.rm!(path)
15
16 extension = String.split(name, ".") |> List.last()
17 query = "#{cgi}?#{extension}"
18
19 with {:ok, %{status_code: 200, body: body}} <- @httpoison.post(query, file_data) do
20 remote_file_name = String.split(body) |> List.first()
21 public_url = "#{files}/#{remote_file_name}.#{extension}"
22 {:ok, public_url}
23 end
24 end
25 end