ObjectID Validator: Refactor.

This commit is contained in:
lain 2020-04-06 13:53:24 +02:00
parent e67cde0ed6
commit 772bc258cd
1 changed files with 8 additions and 8 deletions

View File

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