logo

pleroma

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

object_id.ex (741B)


  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.ObjectID do
  5. use Ecto.Type
  6. def type, do: :string
  7. def cast(object) when is_binary(object) do
  8. # Host has to be present and scheme has to be an http scheme (for now)
  9. case URI.parse(object) do
  10. %URI{host: nil} -> :error
  11. %URI{host: ""} -> :error
  12. %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, object}
  13. _ -> :error
  14. end
  15. end
  16. def cast(%{"id" => object}), do: cast(object)
  17. def cast(_), do: :error
  18. def dump(data), do: {:ok, data}
  19. def load(data), do: {:ok, data}
  20. end