X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fupload%2Ffilter%2Fexiftool.ex;h=4d3a5f551d12837c4f3eff520b7babdf9fa80408;hb=0c8da6466e9fd01b63e9224f9ac18655fd8bf86b;hp=833d8cab4fb707934a566b484da10760fa357e7d;hpb=61675938811a8f2121c857f285d31bd4c7ef3336;p=akkoma
diff --git a/lib/pleroma/upload/filter/exiftool.ex b/lib/pleroma/upload/filter/exiftool.ex
index 833d8cab4..4d3a5f551 100644
--- a/lib/pleroma/upload/filter/exiftool.ex
+++ b/lib/pleroma/upload/filter/exiftool.ex
@@ -1,17 +1,33 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.Exiftool do
+ @moduledoc """
+ Strips GPS related EXIF tags and overwrites the file in place.
+ Also strips or replaces filesystem metadata e.g., timestamps.
+ """
@behaviour Pleroma.Upload.Filter
- @type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
- @type conversions :: conversion() | [conversion()]
+ @spec filter(Pleroma.Upload.t()) :: {:ok, :noop} | {:ok, :filtered} | {:error, String.t()}
+
+ # Formats not compatible with exiftool at this time
+ def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
+ def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
+ def filter(%Pleroma.Upload{content_type: "image/svg+xml"}), do: {:ok, :noop}
+ def filter(%Pleroma.Upload{content_type: "image/jxl"}), do: {:ok, :noop}
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
- System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true)
- :ok
+ try do
+ case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do
+ {_response, 0} -> {:ok, :filtered}
+ {error, 1} -> {:error, error}
+ end
+ rescue
+ e in ErlangError ->
+ {:error, "#{__MODULE__}: #{inspect(e)}"}
+ end
end
- def filter(_), do: :ok
+ def filter(_), do: {:ok, :noop}
end