Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Instances do
  5. @moduledoc "Instances context."
  6. alias Pleroma.Instances.Instance
  7. def filter_reachable(urls_or_hosts), do: Instance.filter_reachable(urls_or_hosts)
  8. def reachable?(url_or_host), do: Instance.reachable?(url_or_host)
  9. def set_reachable(url_or_host), do: Instance.set_reachable(url_or_host)
  10. def set_unreachable(url_or_host, unreachable_since \\ nil),
  11. do: Instance.set_unreachable(url_or_host, unreachable_since)
  12. def get_consistently_unreachable, do: Instance.get_consistently_unreachable()
  13. def set_consistently_unreachable(url_or_host),
  14. do: set_unreachable(url_or_host, reachability_datetime_threshold())
  15. def reachability_datetime_threshold do
  16. federation_reachability_timeout_days =
  17. Pleroma.Config.get([:instance, :federation_reachability_timeout_days], 0)
  18. if federation_reachability_timeout_days > 0 do
  19. NaiveDateTime.add(
  20. NaiveDateTime.utc_now(),
  21. -federation_reachability_timeout_days * 24 * 3600,
  22. :second
  23. )
  24. else
  25. ~N[0000-01-01 00:00:00]
  26. end
  27. end
  28. def host(url_or_host) when is_binary(url_or_host) do
  29. if url_or_host =~ ~r/^http/i do
  30. URI.parse(url_or_host).host
  31. else
  32. url_or_host
  33. end
  34. end
  35. end