1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID do
10 def cast(object) when is_binary(object) do
11 # Host has to be present and scheme has to be an http scheme (for now)
12 case URI.parse(object) do
13 %URI{host: nil} -> :error
14 %URI{host: ""} -> :error
15 %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, object}
20 def cast(%{"id" => object}), do: cast(object)
22 def cast(_), do: :error
24 def dump(data), do: {:ok, data}
26 def load(data), do: {:ok, data}