ObjectID Validator: Refactor.

This commit is contained in:
lain 2020-04-06 13:53:24 +02:00
parent e67cde0ed6
commit 772bc258cd

View File

@ -4,14 +4,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID do
def type, do: :string
def cast(object) when is_binary(object) do
with %URI{
scheme: scheme,
host: host
}
when scheme in ["https", "http"] and not is_nil(host) <-
URI.parse(object) do
# Host has to be present and scheme has to be an http scheme (for now)
case URI.parse(object) do
%URI{host: nil} ->
:error
%URI{scheme: scheme} when scheme in ["https", "http"] ->
{:ok, object}
else
_ ->
:error
end