2019-07-24 09:13:10 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 15:44:49 -07:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-24 09:13:10 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-24 00:26:17 -06:00
|
|
|
defmodule Pleroma.Web.Plugs.SetFormatPlug do
|
2019-07-24 09:13:10 -06:00
|
|
|
import Plug.Conn, only: [assign: 3, fetch_query_params: 1]
|
|
|
|
|
|
|
|
def init(_), do: nil
|
|
|
|
|
|
|
|
def call(conn, _) do
|
|
|
|
case get_format(conn) do
|
|
|
|
nil -> conn
|
|
|
|
format -> assign(conn, :format, format)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp get_format(conn) do
|
|
|
|
conn.private[:phoenix_format] ||
|
|
|
|
case fetch_query_params(conn) do
|
|
|
|
%{query_params: %{"_format" => format}} -> format
|
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|