forked from mirrors/akkoma
c2ca1f22a2
we can't change module attributes and endpoint settings in runtime
37 lines
1 KiB
Elixir
37 lines
1 KiB
Elixir
defmodule Pleroma.Instances do
|
|
@moduledoc "Instances context."
|
|
|
|
@adapter Pleroma.Instances.Instance
|
|
|
|
defdelegate filter_reachable(urls_or_hosts), to: @adapter
|
|
defdelegate reachable?(url_or_host), to: @adapter
|
|
defdelegate set_reachable(url_or_host), to: @adapter
|
|
defdelegate set_unreachable(url_or_host, unreachable_since \\ nil), to: @adapter
|
|
|
|
def set_consistently_unreachable(url_or_host),
|
|
do: set_unreachable(url_or_host, reachability_datetime_threshold())
|
|
|
|
def reachability_datetime_threshold do
|
|
federation_reachability_timeout_days =
|
|
Pleroma.Config.get([:instance, :federation_reachability_timeout_days], 0)
|
|
|
|
if federation_reachability_timeout_days > 0 do
|
|
NaiveDateTime.add(
|
|
NaiveDateTime.utc_now(),
|
|
-federation_reachability_timeout_days * 24 * 3600,
|
|
:second
|
|
)
|
|
else
|
|
~N[0000-01-01 00:00:00]
|
|
end
|
|
end
|
|
|
|
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
|