Merge branch 'suggestion-api-restriction' into 'develop'

Make limit for /api/v1/suggestions

See merge request pleroma/pleroma!334
This commit is contained in:
kaniini 2018-09-09 11:38:33 +00:00
commit b564c23d92
3 changed files with 4 additions and 1 deletions

View file

@ -128,6 +128,7 @@
third_party_engine: third_party_engine:
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}", "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
timeout: 300_000, timeout: 300_000,
limit: 23,
web: "https://vinayaka.distsn.org/?{{host}}+{{user}}" web: "https://vinayaka.distsn.org/?{{host}}+{{user}}"
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom

View file

@ -1148,6 +1148,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
if Keyword.get(@suggestions, :enabled, false) do if Keyword.get(@suggestions, :enabled, false) do
api = Keyword.get(@suggestions, :third_party_engine, "") api = Keyword.get(@suggestions, :third_party_engine, "")
timeout = Keyword.get(@suggestions, :timeout, 5000) timeout = Keyword.get(@suggestions, :timeout, 5000)
limit = Keyword.get(@suggestions, :limit, 23)
host = host =
Application.get_env(:pleroma, Pleroma.Web.Endpoint) Application.get_env(:pleroma, Pleroma.Web.Endpoint)
@ -1161,7 +1162,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
@httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout),
{:ok, data} <- Jason.decode(body) do {:ok, data} <- Jason.decode(body) do
data2 = data2 =
Enum.slice(data, 0, 40) Enum.slice(data, 0, limit)
|> Enum.map(fn x -> |> Enum.map(fn x ->
Map.put( Map.put(
x, x,

View file

@ -59,6 +59,7 @@ def nodeinfo(conn, %{"version" => "2.0"}) do
enabled: Keyword.get(suggestions, :enabled, false), enabled: Keyword.get(suggestions, :enabled, false),
thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""), thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
timeout: Keyword.get(suggestions, :timeout, 5000), timeout: Keyword.get(suggestions, :timeout, 5000),
limit: Keyword.get(suggestions, :limit, 23),
web: Keyword.get(suggestions, :web, "") web: Keyword.get(suggestions, :web, "")
}, },
staffAccounts: staff_accounts, staffAccounts: staff_accounts,