First
[anni] / lib / pleroma / web / plugs / trailing_format_plug.ex
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
5 defmodule Pleroma.Web.Plugs.TrailingFormatPlug do
6   @moduledoc "Calls TrailingFormatPlug for specific paths. Ideally we would just do this in the router, but TrailingFormatPlug needs to be called before Plug.Parsers."
7
8   @behaviour Plug
9   @paths [
10     "/api/statusnet",
11     "/api/statuses",
12     "/api/qvitter",
13     "/api/search",
14     "/api/account",
15     "/api/friends",
16     "/api/mutes",
17     "/api/media",
18     "/api/favorites",
19     "/api/blocks",
20     "/api/friendships",
21     "/api/users",
22     "/users",
23     "/nodeinfo",
24     "/api/help",
25     "/api/externalprofile",
26     "/notice",
27     "/api/pleroma/emoji",
28     "/api/oauth_tokens"
29   ]
30
31   def init(opts) do
32     TrailingFormatPlug.init(opts)
33   end
34
35   for path <- @paths do
36     def call(%{request_path: unquote(path) <> _} = conn, opts) do
37       TrailingFormatPlug.call(conn, opts)
38     end
39   end
40
41   def call(conn, _opts), do: conn
42 end