logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

uri.ex (600B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.Uri do
  5. use Ecto.Type
  6. def type, do: :string
  7. def cast(uri) when is_binary(uri) do
  8. case URI.parse(uri) do
  9. %URI{host: nil} -> :error
  10. %URI{host: ""} -> :error
  11. %URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, uri}
  12. _ -> :error
  13. end
  14. end
  15. def cast(_), do: :error
  16. def dump(data), do: {:ok, data}
  17. def load(data), do: {:ok, data}
  18. end