Revert/simplify.

We only need to check the content-type. There's no chance a webp file
will get mismatched as another image type.
This commit is contained in:
Mark Felder 2020-09-04 22:18:01 -05:00 committed by rinpatch
parent 216c84a8f4
commit 4ea07f74e9
2 changed files with 4 additions and 18 deletions

View File

@ -14,19 +14,9 @@ defmodule Pleroma.Upload.Filter.Exiftool do
# webp is not compatible with exiftool at this time
def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
def filter(%Pleroma.Upload{name: file, tempfile: path, content_type: "image" <> _}) do
if Regex.match?(~r/\.(webp)$/i, file) do
{:ok, :noop}
else
strip_exif(path)
end
end
def filter(_), do: {:ok, :noop}
defp strip_exif(path) do
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
try do
case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", path], parallelism: true) do
case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do
{_response, 0} -> {:ok, :filtered}
{error, 1} -> {:error, error}
end
@ -35,4 +25,6 @@ defp strip_exif(path) do
{:error, "exiftool command not found"}
end
end
def filter(_), do: {:ok, :noop}
end

View File

@ -37,12 +37,6 @@ test "verify webp files are skipped" do
content_type: "image/webp"
}
bad_type = %Pleroma.Upload{
name: "sample.webp",
content_type: "image/jpeg"
}
assert Filter.Exiftool.filter(upload) == {:ok, :noop}
assert Filter.Exiftool.filter(bad_type) == {:ok, :noop}
end
end