uri.ex (442B)
1 defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.Uri do 2 use Ecto.Type 3 4 def type, do: :string 5 6 def cast(uri) when is_binary(uri) do 7 case URI.parse(uri) do 8 %URI{host: nil} -> :error 9 %URI{host: ""} -> :error 10 %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, uri} 11 _ -> :error 12 end 13 end 14 15 def cast(_), do: :error 16 17 def dump(data), do: {:ok, data} 18 19 def load(data), do: {:ok, data} 20 end