2019-11-01 19:47:18 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 16:44:49 -06:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-11-01 19:47:18 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Plugs.StaticFEPlug do
|
2019-11-04 22:02:10 -08:00
|
|
|
import Plug.Conn
|
|
|
|
alias Pleroma.Web.StaticFE.StaticFEController
|
2019-11-01 19:47:18 -07:00
|
|
|
|
2019-11-04 22:02:10 -08:00
|
|
|
def init(options), do: options
|
2019-11-03 12:29:17 -08:00
|
|
|
|
2019-11-01 19:47:18 -07:00
|
|
|
def call(conn, _) do
|
2019-11-04 22:02:10 -08:00
|
|
|
if enabled?() and accepts_html?(conn) do
|
|
|
|
conn
|
|
|
|
|> StaticFEController.call(:show)
|
|
|
|
|> halt()
|
2019-11-03 12:29:17 -08:00
|
|
|
else
|
2019-11-04 22:02:10 -08:00
|
|
|
conn
|
2019-11-01 19:47:18 -07:00
|
|
|
end
|
|
|
|
end
|
2019-11-04 22:02:10 -08:00
|
|
|
|
2019-11-07 19:31:28 -08:00
|
|
|
defp enabled?, do: Pleroma.Config.get([:static_fe, :enabled], false)
|
2019-11-04 22:02:10 -08:00
|
|
|
|
|
|
|
defp accepts_html?(conn) do
|
2020-02-29 18:53:49 -08:00
|
|
|
case get_req_header(conn, "accept") do
|
|
|
|
[accept | _] -> String.contains?(accept, "text/html")
|
|
|
|
_ -> false
|
|
|
|
end
|
2019-11-04 22:02:10 -08:00
|
|
|
end
|
2019-11-01 19:47:18 -07:00
|
|
|
end
|