Add `account_activation_required` to /api/v1/instance
[akkoma] / lib / pleroma / ecto_type / activity_pub / object_validators / uri.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.Uri do
6 use Ecto.Type
7
8 def type, do: :string
9
10 def cast(uri) when is_binary(uri) do
11 case URI.parse(uri) do
12 %URI{host: nil} -> :error
13 %URI{host: ""} -> :error
14 %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, uri}
15 _ -> :error
16 end
17 end
18
19 def cast(_), do: :error
20
21 def dump(data), do: {:ok, data}
22
23 def load(data), do: {:ok, data}
24 end