summaryrefslogtreecommitdiff
path: root/lib/pleroma/instances.ex
blob: 6d445d6b3a075eb600d5a3f25ccba4fee184628a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
defmodule Pleroma.Instances do
  @moduledoc "Instances context."

  @adapter Pleroma.Instances.Instance

  defdelegate filter_reachable(urls), to: @adapter
  defdelegate reachable?(url), to: @adapter
  defdelegate set_reachable(url), to: @adapter
  defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter

  def reachability_time_threshold,
    do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second)

  def host(url_or_host) when is_binary(url_or_host) do
    if url_or_host =~ ~r/^http/i do
      URI.parse(url_or_host).host
    else
      url_or_host
    end
  end
end