[#2497] Specified SHELL in .gitlab-ci.yml as required for `exexec`.
[akkoma] / lib / pleroma / ecto_type / activity_pub / object_validators / object_id.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID do
6 use Ecto.Type
7
8 def type, do: :string
9
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}
16 _ -> :error
17 end
18 end
19
20 def cast(%{"id" => object}), do: cast(object)
21
22 def cast(_), do: :error
23
24 def dump(data), do: {:ok, data}
25
26 def load(data), do: {:ok, data}
27 end