From 0c9c62509d10c19e2e6d796cb431f1560e9e88b1 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Sat, 11 Jan 2020 17:19:54 +0000 Subject: [PATCH] Remove MDII uploader --- CHANGELOG.md | 1 + config/config.exs | 4 --- config/description.exs | 17 ------------ lib/pleroma/uploaders/mdii.ex | 37 -------------------------- test/uploaders/mdii_test.exs | 50 ----------------------------------- 5 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 lib/pleroma/uploaders/mdii.ex delete mode 100644 test/uploaders/mdii_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f199b3d..04efc97c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Removed - **Breaking**: Removed 1.0+ deprecated configurations `Pleroma.Upload, :strip_exif` and `:instance, :dedupe_media` - **Breaking**: OStatus protocol support +- **Breaking**: MDII uploader ### Changed - **Breaking:** Elixir >=1.8 is now required (was >= 1.7) diff --git a/config/config.exs b/config/config.exs index 103361b29..d41abf090 100644 --- a/config/config.exs +++ b/config/config.exs @@ -108,10 +108,6 @@ streaming_enabled: true, public_endpoint: "https://s3.amazonaws.com" -config :pleroma, Pleroma.Uploaders.MDII, - cgi: "https://mdii.sakura.ne.jp/mdii-post.cgi", - files: "https://mdii.sakura.ne.jp" - config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"], pack_extensions: [".png", ".gif"], diff --git a/config/description.exs b/config/description.exs index 45e4b43f1..1089fd86c 100644 --- a/config/description.exs +++ b/config/description.exs @@ -2557,23 +2557,6 @@ } ] }, - %{ - group: :pleroma, - key: Pleroma.Uploaders.MDII, - type: :group, - children: [ - %{ - key: :cgi, - type: :string, - suggestions: ["https://mdii.sakura.ne.jp/mdii-post.cgi"] - }, - %{ - key: :files, - type: :string, - suggestions: ["https://mdii.sakura.ne.jp"] - } - ] - }, %{ group: :pleroma, key: :http, diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex deleted file mode 100644 index c36f3d61d..000000000 --- a/lib/pleroma/uploaders/mdii.ex +++ /dev/null @@ -1,37 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Uploaders.MDII do - @moduledoc "Represents uploader for https://github.com/hakaba-hitoyo/minimal-digital-image-infrastructure" - - alias Pleroma.Config - alias Pleroma.HTTP - - @behaviour Pleroma.Uploaders.Uploader - - # 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 - - def put_file(upload) do - cgi = Config.get([Pleroma.Uploaders.MDII, :cgi]) - files = Config.get([Pleroma.Uploaders.MDII, :files]) - - {:ok, file_data} = File.read(upload.tempfile) - - extension = String.split(upload.name, ".") |> List.last() - query = "#{cgi}?#{extension}" - - with {:ok, %{status: 200, body: body}} <- - HTTP.post(query, file_data, [], adapter: [pool: :default]) do - remote_file_name = String.split(body) |> List.first() - public_url = "#{files}/#{remote_file_name}.#{extension}" - {:ok, {:url, public_url}} - else - _ -> Pleroma.Uploaders.Local.put_file(upload) - end - end -end diff --git a/test/uploaders/mdii_test.exs b/test/uploaders/mdii_test.exs deleted file mode 100644 index d432d40f0..000000000 --- a/test/uploaders/mdii_test.exs +++ /dev/null @@ -1,50 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Uploaders.MDIITest do - use Pleroma.DataCase - alias Pleroma.Uploaders.MDII - import Tesla.Mock - - describe "get_file/1" do - test "it returns path to local folder for files" do - assert MDII.get_file("") == {:ok, {:static_dir, "test/uploads"}} - end - end - - describe "put_file/1" do - setup do - file_upload = %Pleroma.Upload{ - name: "mdii-image.jpg", - content_type: "image/jpg", - path: "test_folder/mdii-image.jpg", - tempfile: Path.absname("test/fixtures/image_tmp.jpg") - } - - [file_upload: file_upload] - end - - test "save file", %{file_upload: file_upload} do - mock(fn - %{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} -> - %Tesla.Env{status: 200, body: "mdii-image"} - end) - - assert MDII.put_file(file_upload) == - {:ok, {:url, "https://mdii.sakura.ne.jp/mdii-image.jpg"}} - end - - test "save file to local if MDII isn`t available", %{file_upload: file_upload} do - mock(fn - %{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} -> - %Tesla.Env{status: 500} - end) - - assert MDII.put_file(file_upload) == :ok - - assert Path.join([Pleroma.Uploaders.Local.upload_path(), file_upload.path]) - |> File.exists?() - end - end -end