Make oauth pages translatable
[akkoma] / lib / pleroma / instances.ex
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
5 defmodule Pleroma.Instances do
6 @moduledoc "Instances context."
7
8 alias Pleroma.Instances.Instance
9
10 def filter_reachable(urls_or_hosts), do: Instance.filter_reachable(urls_or_hosts)
11
12 def reachable?(url_or_host), do: Instance.reachable?(url_or_host)
13
14 def set_reachable(url_or_host), do: Instance.set_reachable(url_or_host)
15
16 def set_unreachable(url_or_host, unreachable_since \\ nil),
17 do: Instance.set_unreachable(url_or_host, unreachable_since)
18
19 def get_consistently_unreachable, do: Instance.get_consistently_unreachable()
20
21 def set_consistently_unreachable(url_or_host),
22 do: set_unreachable(url_or_host, reachability_datetime_threshold())
23
24 def reachability_datetime_threshold do
25 federation_reachability_timeout_days =
26 Pleroma.Config.get([:instance, :federation_reachability_timeout_days], 0)
27
28 if federation_reachability_timeout_days > 0 do
29 NaiveDateTime.add(
30 NaiveDateTime.utc_now(),
31 -federation_reachability_timeout_days * 24 * 3600,
32 :second
33 )
34 else
35 ~N[0000-01-01 00:00:00]
36 end
37 end
38
39 def host(url_or_host) when is_binary(url_or_host) do
40 if url_or_host =~ ~r/^http/i do
41 URI.parse(url_or_host).host
42 else
43 url_or_host
44 end
45 end
46 end