omplement mdii uploader
authorHakaba Hitoyo <hakabahitoyo@example.com>
Thu, 15 Nov 2018 05:38:45 +0000 (14:38 +0900)
committerHakaba Hitoyo <hakabahitoyo@example.com>
Thu, 15 Nov 2018 05:38:45 +0000 (14:38 +0900)
lib/pleroma/uploaders/mdii.ex

index 3cf71df432b9467ff6c1eace327668228b3f3c18..f21a7e1e2c55350243878171f0b5ac228897e50d 100644 (file)
@@ -1,6 +1,8 @@
 defmodule Pleroma.Uploaders.Mdii do
   @behaviour Pleroma.Uploaders.Uploader
 
+  @httpoison Application.get_env(:pleroma, :httpoison)
+
   def put_file(name, uuid, path, content_type, _should_dedupe) do
     settings = Application.get_env(:pleroma, Pleroma.Uploaders.Mdii)
     host_name = Keyword.fetch!(settings, :host_name)
@@ -8,12 +10,15 @@ defmodule Pleroma.Uploaders.Mdii do
     {:ok, file_data} = File.read(path)
 
     File.rm!(path)
+    
+    extension = Regex.replace(~r/^image\//, content_type, "")
+    query = "https://#{host_name}/mdii.cgi?#{extension}"
 
-    remote_file_name = "00000"
-    extension = "png"
-
-    public_url = "https://#{host_name}/#{remote_file_name}.#{extension}"
-
-    {:ok, public_url}
+    with {:ok, %{status_code: 200, body: body}} <-
+           @httpoison.get(url, file_data) do
+      remote_file_name = body
+      public_url = "https://#{host_name}/#{remote_file_name}.#{extension}"
+      {:ok, public_url}
+    end
   end
 end