Validators: ObjectID is an http uri.
This commit is contained in:
parent
f6835333be
commit
643f15e77b
2 changed files with 50 additions and 4 deletions
|
|
@ -4,12 +4,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID do
|
|||
def type, do: :string
|
||||
|
||||
def cast(object) when is_binary(object) do
|
||||
{:ok, object}
|
||||
with %URI{
|
||||
scheme: scheme,
|
||||
host: host
|
||||
}
|
||||
when scheme in ["https", "http"] and not is_nil(host) <-
|
||||
URI.parse(object) do
|
||||
{:ok, object}
|
||||
else
|
||||
_ ->
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
def cast(%{"id" => object}) when is_binary(object) do
|
||||
{:ok, object}
|
||||
end
|
||||
def cast(%{"id" => object}), do: cast(object)
|
||||
|
||||
def cast(_) do
|
||||
:error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue