logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

federating_plug.ex (731B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Plugs.FederatingPlug do
  5. import Plug.Conn
  6. def init(options) do
  7. options
  8. end
  9. def call(conn, _opts) do
  10. if federating?() do
  11. conn
  12. else
  13. fail(conn)
  14. end
  15. end
  16. def federating?, do: Pleroma.Config.get([:instance, :federating])
  17. # Definition for the use in :if_func / :unless_func plug options
  18. def federating?(_conn), do: federating?()
  19. defp fail(conn) do
  20. conn
  21. |> put_status(404)
  22. |> Phoenix.Controller.put_view(Pleroma.Web.ErrorView)
  23. |> Phoenix.Controller.render("404.json")
  24. |> halt()
  25. end
  26. end