Bypass the filter based on content-type as well in case a webp image is uploaded...
[akkoma] / lib / pleroma / upload / filter / exiftool.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Upload.Filter.Exiftool do
6 @moduledoc """
7 Strips GPS related EXIF tags and overwrites the file in place.
8 Also strips or replaces filesystem metadata e.g., timestamps.
9 """
10 @behaviour Pleroma.Upload.Filter
11
12 @spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
13
14 # webp is not compatible with exiftool at this time
15 def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
16
17 def filter(%Pleroma.Upload{name: file, tempfile: path, content_type: "image" <> _}) do
18 if Regex.match?(~r/\.(webp)$/i, file) do
19 {:ok, :noop}
20 else
21 strip_exif(path)
22 end
23 end
24
25 def filter(_), do: {:ok, :noop}
26
27 defp strip_exif(path) do
28 try do
29 case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", path], parallelism: true) do
30 {_response, 0} -> {:ok, :filtered}
31 {error, 1} -> {:error, error}
32 end
33 rescue
34 _e in ErlangError ->
35 {:error, "exiftool command not found"}
36 end
37 end
38 end