object_id.ex (583B)
1 defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID do 2 use Ecto.Type 3 4 def type, do: :string 5 6 def cast(object) when is_binary(object) do 7 # Host has to be present and scheme has to be an http scheme (for now) 8 case URI.parse(object) do 9 %URI{host: nil} -> :error 10 %URI{host: ""} -> :error 11 %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, object} 12 _ -> :error 13 end 14 end 15 16 def cast(%{"id" => object}), do: cast(object) 17 18 def cast(_), do: :error 19 20 def dump(data), do: {:ok, data} 21 22 def load(data), do: {:ok, data} 23 end