logo

pleroma

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

set_format_plug.ex (619B)


  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.SetFormatPlug do
  5. import Plug.Conn, only: [assign: 3, fetch_query_params: 1]
  6. def init(_), do: nil
  7. def call(conn, _) do
  8. case get_format(conn) do
  9. nil -> conn
  10. format -> assign(conn, :format, format)
  11. end
  12. end
  13. defp get_format(conn) do
  14. conn.private[:phoenix_format] ||
  15. case fetch_query_params(conn) do
  16. %{query_params: %{"_format" => format}} -> format
  17. _ -> nil
  18. end
  19. end
  20. end