X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fupload%2Ffilter%2Fmogrifun.ex;h=69885a0bd66bbcba022118c88280c82b1e5466ea;hb=0c8da6466e9fd01b63e9224f9ac18655fd8bf86b;hp=fee49fb5100590cc50f0e0c742e2506d05eafd64;hpb=9570a5be405c4cf4f07907eab4ced21e07fa20c9;p=akkoma
diff --git a/lib/pleroma/upload/filter/mogrifun.ex b/lib/pleroma/upload/filter/mogrifun.ex
index fee49fb51..69885a0bd 100644
--- a/lib/pleroma/upload/filter/mogrifun.ex
+++ b/lib/pleroma/upload/filter/mogrifun.ex
@@ -1,11 +1,15 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.Mogrifun do
@behaviour Pleroma.Upload.Filter
alias Pleroma.Upload.Filter
+ @moduledoc """
+ This module is just an example of an Upload filter. It's not supposed to be used in production.
+ """
+
@filters [
{"implode", "1"},
{"-raise", "20"},
@@ -34,11 +38,16 @@ defmodule Pleroma.Upload.Filter.Mogrifun do
[{"fill", "yellow"}, {"tint", "40"}]
]
+ @spec filter(Pleroma.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
- Filter.Mogrify.do_filter(file, [Enum.random(@filters)])
-
- :ok
+ try do
+ Filter.Mogrify.do_filter(file, [Enum.random(@filters)])
+ {:ok, :filtered}
+ rescue
+ e in ErlangError ->
+ {:error, "#{__MODULE__}: #{inspect(e)}"}
+ end
end
- def filter(_), do: :ok
+ def filter(_), do: {:ok, :noop}
end