logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

strip_location.ex (1185B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Upload.Filter.Exiftool.StripLocation do
  5. @moduledoc """
  6. Strips GPS related EXIF tags and overwrites the file in place.
  7. Also strips or replaces filesystem metadata e.g., timestamps.
  8. """
  9. @behaviour Pleroma.Upload.Filter
  10. @spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
  11. # Formats not compatible with exiftool at this time
  12. def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
  13. def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
  14. def filter(%Pleroma.Upload{content_type: "image/svg" <> _}), do: {:ok, :noop}
  15. def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
  16. try do
  17. case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do
  18. {_response, 0} -> {:ok, :filtered}
  19. {error, 1} -> {:error, error}
  20. end
  21. rescue
  22. e in ErlangError ->
  23. {:error, "#{__MODULE__}: #{inspect(e)}"}
  24. end
  25. end
  26. def filter(_), do: {:ok, :noop}
  27. end