Merge branch 'following-relationships-optimizations' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / object_validators / types / object_id.ex
1 defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID do
2 use Ecto.Type
3
4 def type, do: :string
5
6 def cast(object) when is_binary(object) do
7 # Host has to be present and scheme has to be an http scheme (for now)
8 case URI.parse(object) do
9 %URI{host: nil} -> :error
10 %URI{host: ""} -> :error
11 %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, object}
12 _ -> :error
13 end
14 end
15
16 def cast(%{"id" => object}), do: cast(object)
17
18 def cast(_) do
19 :error
20 end
21
22 def dump(data) do
23 {:ok, data}
24 end
25
26 def load(data) do
27 {:ok, data}
28 end
29 end