24 lines
458 B
Elixir
24 lines
458 B
Elixir
defmodule ClacksWeb.Plug.Format do
|
|
import Plug.Conn
|
|
|
|
def init(opts), do: opts
|
|
|
|
def call(conn, _opts) do
|
|
conn = fetch_query_params(conn)
|
|
|
|
format =
|
|
case conn.query_params do
|
|
%{"format" => format} when format in ["activity+json", "html"] ->
|
|
format
|
|
|
|
%{"format" => "json"} ->
|
|
"activity+json"
|
|
|
|
_ ->
|
|
Phoenix.Controller.get_format(conn)
|
|
end
|
|
|
|
assign(conn, :format, format)
|
|
end
|
|
end
|