fallbacking into local uploader
authorhakabahitoyo <hakabahitoyo@example.com>
Sat, 17 Nov 2018 11:16:25 +0000 (20:16 +0900)
committerhakabahitoyo <hakabahitoyo@example.com>
Sat, 17 Nov 2018 11:16:25 +0000 (20:16 +0900)
lib/pleroma/uploaders/mdii.ex

index b0c7e19e798fa90f2bacaef4480baf4747caf407..a9d52b0dcf61d71358ce55a8d772795159cb9040 100644 (file)
@@ -5,21 +5,22 @@ defmodule Pleroma.Uploaders.MDII do
 
   @httpoison Application.get_env(:pleroma, :httpoison)
 
-  def put_file(name, uuid, path, content_type, _should_dedupe) do
+  def put_file(name, uuid, path, content_type, should_dedupe) do
     cgi = Pleroma.Config.get([Pleroma.Uploaders.MDII, :cgi])
     files = Pleroma.Config.get([Pleroma.Uploaders.MDII, :files])
 
     {:ok, file_data} = File.read(path)
 
-    File.rm!(path)
-
     extension = String.split(name, ".") |> List.last()
     query = "#{cgi}?#{extension}"
 
     with {:ok, %{status_code: 200, body: body}} <- @httpoison.post(query, file_data) do
+      File.rm!(path)
       remote_file_name = String.split(body) |> List.first()
       public_url = "#{files}/#{remote_file_name}.#{extension}"
       {:ok, public_url}
+    else
+      _ -> Pleroma.Uploaders.Local.put_file(name, uuid, path, content_type, should_dedupe)
     end
   end
 end