2019-11-01 20:47:18 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-11-01 20:47:18 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-24 00:06:10 -06:00
|
|
|
defmodule Pleroma.Web.Plugs.StaticFEPlug do
|
2019-11-04 23:02:10 -07:00
|
|
|
import Plug.Conn
|
|
|
|
alias Pleroma.Web.StaticFE.StaticFEController
|
2019-11-01 20:47:18 -06:00
|
|
|
|
2019-11-04 23:02:10 -07:00
|
|
|
def init(options), do: options
|
2019-11-03 13:29:17 -07:00
|
|
|
|
2019-11-01 20:47:18 -06:00
|
|
|
def call(conn, _) do
|
2022-12-07 06:35:00 -07:00
|
|
|
if enabled?() and requires_html?(conn) and not_logged_in?(conn) do
|
2019-11-04 23:02:10 -07:00
|
|
|
conn
|
|
|
|
|> StaticFEController.call(:show)
|
|
|
|
|> halt()
|
2019-11-03 13:29:17 -07:00
|
|
|
else
|
2019-11-04 23:02:10 -07:00
|
|
|
conn
|
2019-11-01 20:47:18 -06:00
|
|
|
end
|
|
|
|
end
|
2019-11-04 23:02:10 -07:00
|
|
|
|
2019-11-07 20:31:28 -07:00
|
|
|
defp enabled?, do: Pleroma.Config.get([:static_fe, :enabled], false)
|
2019-11-04 23:02:10 -07:00
|
|
|
|
2020-06-26 08:27:39 -06:00
|
|
|
defp requires_html?(conn) do
|
2020-07-06 04:11:10 -06:00
|
|
|
Phoenix.Controller.get_format(conn) == "html"
|
2019-11-04 23:02:10 -07:00
|
|
|
end
|
2022-12-07 06:35:00 -07:00
|
|
|
|
|
|
|
defp not_logged_in?(%{assigns: %{user: %Pleroma.User{}}}), do: false
|
|
|
|
defp not_logged_in?(_), do: true
|
2019-11-01 20:47:18 -06:00
|
|
|
end
|