logo

pleroma

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

strip_location.ex (1148B)


  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. # Formats not compatible with exiftool at this time
  11. def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
  12. def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
  13. def filter(%Pleroma.Upload{content_type: "image/svg" <> _}), do: {:ok, :noop}
  14. def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
  15. try do
  16. case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", "-png:all=", file],
  17. parallelism: true
  18. ) do
  19. {_response, 0} -> {:ok, :filtered}
  20. {error, 1} -> {:error, error}
  21. end
  22. rescue
  23. e in ErlangError ->
  24. {:error, "#{__MODULE__}: #{inspect(e)}"}
  25. end
  26. end
  27. def filter(_), do: {:ok, :noop}
  28. end