2019-07-10 05:13:23 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-07-10 05:13:23 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
2019-01-23 18:37:25 +03:00
|
|
|
defmodule Pleroma.Instances do
|
|
|
|
|
@moduledoc "Instances context."
|
|
|
|
|
|
2021-06-08 18:03:21 -05:00
|
|
|
alias Pleroma.Instances.Instance
|
2019-01-23 18:37:25 +03:00
|
|
|
|
2023-12-27 12:43:12 -05:00
|
|
|
defdelegate filter_reachable(urls_or_hosts), to: Instance
|
2021-06-08 18:03:21 -05:00
|
|
|
|
2023-12-27 12:43:12 -05:00
|
|
|
defdelegate reachable?(url_or_host), to: Instance
|
2021-06-08 18:03:21 -05:00
|
|
|
|
2023-12-27 12:43:12 -05:00
|
|
|
defdelegate set_reachable(url_or_host), to: Instance
|
2021-06-08 18:03:21 -05:00
|
|
|
|
2023-12-27 12:43:12 -05:00
|
|
|
defdelegate set_unreachable(url_or_host, unreachable_since \\ nil), to: Instance
|
2021-06-08 18:03:21 -05:00
|
|
|
|
2025-06-05 16:38:40 -07:00
|
|
|
defdelegate get_unreachable, to: Instance
|
2019-01-24 19:15:23 +03:00
|
|
|
|
|
|
|
|
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
|
2025-06-28 12:51:10 -07:00
|
|
|
|
|
|
|
|
@doc "Schedules reachability checks for all unreachable instances"
|
|
|
|
|
def check_all_unreachable do
|
|
|
|
|
get_unreachable()
|
|
|
|
|
|> Enum.each(fn {domain, _} ->
|
|
|
|
|
Pleroma.Workers.ReachabilityWorker.new(%{"domain" => domain})
|
|
|
|
|
|> Oban.insert()
|
|
|
|
|
end)
|
|
|
|
|
end
|
2025-06-28 13:23:37 -07:00
|
|
|
|
|
|
|
|
@doc "Deletes all users and activities for unreachable instances"
|
|
|
|
|
def delete_all_unreachable do
|
|
|
|
|
get_unreachable()
|
|
|
|
|
|> Enum.each(fn {domain, _} ->
|
2025-06-28 13:37:06 -07:00
|
|
|
Instance.delete(domain)
|
2025-06-28 13:23:37 -07:00
|
|
|
end)
|
|
|
|
|
end
|
2019-01-23 18:37:25 +03:00
|
|
|
end
|