logo

pleroma

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

emoji.ex (899B)


  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.EctoType.ActivityPub.ObjectValidators.Emoji do
  5. use Ecto.Type
  6. def type, do: :map
  7. def cast(data) when is_map(data) do
  8. has_invalid_emoji? =
  9. Enum.find(data, fn
  10. {name, uri} when is_binary(name) and is_binary(uri) ->
  11. # based on ObjectValidators.Uri.cast()
  12. case URI.parse(uri) do
  13. %URI{host: nil} -> true
  14. %URI{host: ""} -> true
  15. %URI{scheme: scheme} when scheme in ["https", "http"] -> false
  16. _ -> true
  17. end
  18. {_name, _uri} ->
  19. true
  20. end)
  21. if has_invalid_emoji?, do: :error, else: {:ok, data}
  22. end
  23. def cast(_data), do: :error
  24. def dump(data), do: {:ok, data}
  25. def load(data), do: {:ok, data}
  26. end