X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuploaders%2Fmdii.ex;h=190ed9f3ac77e93fa5494597deb6bc113e96b887;hb=1452a96ad6cfd7d250e3f7c10805994cc92016a7;hp=71f3d1be7a56ebb6850cec843cf8a8c1bbf301f3;hpb=52224de39fe757077448853a7e1546c0f01509af;p=akkoma diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index 71f3d1be7..190ed9f3a 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -1,23 +1,36 @@ -defmodule Pleroma.Uploaders.Mdii do +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Uploaders.MDII do + alias Pleroma.Config + @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) + # MDII-hosted images are never passed through the MediaPlug; only local media. + # Delegate to Pleroma.Uploaders.Local + def get_file(file) do + Pleroma.Uploaders.Local.get_file(file) + end - {:ok, file_data} = File.read(path) + def put_file(upload) do + cgi = Config.get([Pleroma.Uploaders.MDII, :cgi]) + files = Config.get([Pleroma.Uploaders.MDII, :files]) - File.rm!(path) + {:ok, file_data} = File.read(upload.tempfile) - extension = String.split(name, ".") |> List.last() - query = "https://#{host_name}/mdii-post.cgi?#{extension}" + extension = String.split(upload.name, ".") |> List.last() + query = "#{cgi}?#{extension}" - with {:ok, %{status_code: 200, body: body}} <- @httpoison.post(query, file_data) do + with {:ok, %{status: 200, body: body}} <- + @httpoison.post(query, file_data, [], adapter: [pool: :default]) do remote_file_name = String.split(body) |> List.first() - public_url = "https://#{host_name}/#{remote_file_name}.#{extension}" - {:ok, public_url} + public_url = "#{files}/#{remote_file_name}.#{extension}" + {:ok, {:url, public_url}} + else + _ -> Pleroma.Uploaders.Local.put_file(upload) end end end