Pleroma.ApplicationRequirements.verify!()
setup_instrumenters()
load_custom_modules()
+ check_system_commands()
Pleroma.Docs.JSON.compile()
adapter = Application.get_env(:tesla, :adapter)
end
defp http_children(_, _), do: []
+
+ defp check_system_commands do
+ filters = Config.get([Pleroma.Upload, :filters])
+
+ check_filter = fn filter, command_required ->
+ with true <- filter in filters,
+ false <- Pleroma.Utils.command_available?(command_required) do
+ Logger.error(
+ "#{filter} is specified in list of Pleroma.Upload filters, but the #{command_required} command is not found"
+ )
+ end
+ end
+
+ check_filter.(Pleroma.Upload.Filters.Exiftool, "exiftool")
+ check_filter.(Pleroma.Upload.Filters.Mogrify, "mogrify")
+ check_filter.(Pleroma.Upload.Filters.Mogrifun, "mogrify")
+ end
end
"""
@behaviour Pleroma.Upload.Filter
+ @spec filter(Pleroma.Upload.t()) :: :ok | {:error, String.t()}
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
- if Pleroma.Utils.command_available?("exiftool") do
- System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true)
- :ok
- else
- {:error, "exiftool command not found"}
+ try do
+ case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do
+ {_response, 0} -> :ok
+ {error, 1} -> {:error, error}
+ end
+ rescue
+ _e in ErlangError ->
+ {:error, "exiftool command not found"}
end
end
[{"fill", "yellow"}, {"tint", "40"}]
]
+ @spec filter(Pleroma.Upload.t()) :: :ok | {:error, String.t()}
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
- if Pleroma.Utils.command_available?("mogrify") do
+ try do
Filter.Mogrify.do_filter(file, [Enum.random(@filters)])
:ok
- else
- {:error, "mogrify command not found"}
+ rescue
+ _e in ErlangError ->
+ {:error, "mogrify command not found"}
end
end
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
@type conversions :: conversion() | [conversion()]
+ @spec filter(Pleroma.Upload.t()) :: :ok | {:error, String.t()}
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
- if Pleroma.Utils.command_available?("mogrify") do
- filters = Pleroma.Config.get!([__MODULE__, :args])
-
- do_filter(file, filters)
+ try do
+ do_filter(file, Pleroma.Config.get!([__MODULE__, :args]))
:ok
- else
- {:error, "mogrify command not found"}
+ rescue
+ _e in ErlangError ->
+ {:error, "mogrify command not found"}
end
end