From f944f8157ac078aef5edda64059a5d6d3837bf53 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 00:21:38 +0900 Subject: [PATCH 01/17] /api/v1/suggestions endpoint --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 +++++ lib/pleroma/web/router.ex | 2 ++ 2 files changed, 7 insertions(+) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 09e6b0b59..0184d52c8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1070,4 +1070,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> put_status(500) |> json("Something went wrong") end + + def suggestions(conn, _) do + conn + |> json("SUGGESTIONS!") + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 34652cdde..f1c08c681 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -140,6 +140,8 @@ defmodule Pleroma.Web.Router do get("/domain_blocks", MastodonAPIController, :domain_blocks) post("/domain_blocks", MastodonAPIController, :block_domain) delete("/domain_blocks", MastodonAPIController, :unblock_domain) + + get("/suggestions", MastodonAPIController, :suggestions) end scope "/api/web", Pleroma.Web.MastodonAPI do From 4a21c1b343c3f62d78da1651ed490daf4dde5d97 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 00:44:18 +0900 Subject: [PATCH 02/17] mock /api/v1/suggestions --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 0184d52c8..0f50eba84 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1071,8 +1071,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> json("Something went wrong") end - def suggestions(conn, _) do + def suggestions(%{assigns: %{user: user}} = conn, _) do + res = %{ + host: (String.replace Web.base_url(), "https://", ""), + user: user.nickname + } conn - |> json("SUGGESTIONS!") + |> json(res) end end From 3812b627ca546287e20a55cd49544a36eefffa0b Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 00:52:23 +0900 Subject: [PATCH 03/17] better mock /api/v1/suggestions --- .../mastodon_api/mastodon_api_controller.ex | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 0f50eba84..fb334352d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1072,10 +1072,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def suggestions(%{assigns: %{user: user}} = conn, _) do - res = %{ - host: (String.replace Web.base_url(), "https://", ""), - user: user.nickname - } + res = [ + %{ + username: "vaginaplant", + acct: "vaginaplant@3.distsn.org", + display_name: "Hakaba Hitoyo", + note: "Recommendation Fairness Warrior", + avatar: "https://3.distsn.org/media/1c0cbe9d-8b87-496f-b964-1af8116b8f67/D38B0A8B021DC5565D06CF40EBB744E4B7CF8F7F16347094F9CD469348DCC267.jpeg", + avatar_static: "https://3.distsn.org/media/1c0cbe9d-8b87-496f-b964-1af8116b8f67/D38B0A8B021DC5565D06CF40EBB744E4B7CF8F7F16347094F9CD469348DCC267.jpeg" + }, + %{ + username: user.nickname, + acct: user.nickname <> "@" <> (String.replace Web.base_url(), "https://", "") + } + ] conn |> json(res) end From eb0afda3a72aa08a991e25b05c98ae798655f413 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 10:04:37 +0900 Subject: [PATCH 04/17] http access to third party user recommendation --- .../mastodon_api/mastodon_api_controller.ex | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index fb334352d..4f48a141b 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -11,6 +11,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do import Ecto.Query require Logger + @httpoison Application.get_env(:pleroma, :httpoison) + action_fallback(:errors) def create_app(conn, params) do @@ -1072,21 +1074,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def suggestions(%{assigns: %{user: user}} = conn, _) do - res = [ - %{ - username: "vaginaplant", - acct: "vaginaplant@3.distsn.org", - display_name: "Hakaba Hitoyo", - note: "Recommendation Fairness Warrior", - avatar: "https://3.distsn.org/media/1c0cbe9d-8b87-496f-b964-1af8116b8f67/D38B0A8B021DC5565D06CF40EBB744E4B7CF8F7F16347094F9CD469348DCC267.jpeg", - avatar_static: "https://3.distsn.org/media/1c0cbe9d-8b87-496f-b964-1af8116b8f67/D38B0A8B021DC5565D06CF40EBB744E4B7CF8F7F16347094F9CD469348DCC267.jpeg" - }, - %{ - username: user.nickname, - acct: user.nickname <> "@" <> (String.replace Web.base_url(), "https://", "") - } - ] - conn - |> json(res) + host = String.replace Web.base_url(), "https://", "" + user = user.nickname + api = "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-filtered-api.cgi?{{host}}+{{user}}" + url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) + with {:ok, %{status_code: 200, body: body}} <- + @httpoison.get(url), + {:ok, data} <- Jason.decode(body) do + conn + |> json(data) + else + e -> Logger.error("Could not decode user at fetch #{url}, #{inspect(e)}") + end end end From 127882a5d51d8243eae44ad7ed73bf6010804760 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 11:41:09 +0900 Subject: [PATCH 05/17] configurable --- config/config.exs | 3 +++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 0616fe4fb..9299d0dc6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -95,6 +95,9 @@ config :pleroma, :gopher, ip: {0, 0, 0, 0}, port: 9999 +config :pleroma, :suggestions, + third_party_engine: "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-filtered-api.cgi?{{host}}+{{user}}" + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 4f48a141b..fd60db3d6 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1073,10 +1073,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> json("Something went wrong") end + @suggestions Application.get_env(:pleroma, :suggestions) + def suggestions(%{assigns: %{user: user}} = conn, _) do host = String.replace Web.base_url(), "https://", "" user = user.nickname - api = "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-filtered-api.cgi?{{host}}+{{user}}" + api = Keyword.get(@suggestions, :third_party_engine, "") url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(url), From f96244006e22740036effd9b6ef3ac753250494e Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 12:07:09 +0900 Subject: [PATCH 06/17] change api --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 9299d0dc6..1f69e6244 100644 --- a/config/config.exs +++ b/config/config.exs @@ -96,7 +96,7 @@ config :pleroma, :gopher, port: 9999 config :pleroma, :suggestions, - third_party_engine: "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-filtered-api.cgi?{{host}}+{{user}}" + third_party_engine: "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. From 2eeaf01627efb2a13d73f4cde764d3cb1fef3e98 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 14 Jul 2018 14:03:30 +0900 Subject: [PATCH 07/17] id field --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index fd60db3d6..d87a6cb19 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1081,10 +1081,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do api = Keyword.get(@suggestions, :third_party_engine, "") url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status_code: 200, body: body}} <- - @httpoison.get(url), + @httpoison.get(url, [], [timeout: 300000, recv_timeout: 300000]), {:ok, data} <- Jason.decode(body) do + data2 = Enum.slice(data, 0, 40) |> Enum.map(fn(x) -> + Map.put(x, "id", User.get_or_fetch(x["acct"]).id) + end) conn - |> json(data) + |> json(data2) else e -> Logger.error("Could not decode user at fetch #{url}, #{inspect(e)}") end From e7c580828c109247de11624bae8c7286b02441e5 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sun, 15 Jul 2018 20:36:26 +0900 Subject: [PATCH 08/17] format --- config/config.exs | 3 ++- .../web/mastodon_api/mastodon_api_controller.ex | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config/config.exs b/config/config.exs index 1f69e6244..3583e7b46 100644 --- a/config/config.exs +++ b/config/config.exs @@ -96,7 +96,8 @@ config :pleroma, :gopher, port: 9999 config :pleroma, :suggestions, - third_party_engine: "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" + third_party_engine: + "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index d87a6cb19..e397b911d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1076,16 +1076,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @suggestions Application.get_env(:pleroma, :suggestions) def suggestions(%{assigns: %{user: user}} = conn, _) do - host = String.replace Web.base_url(), "https://", "" + host = String.replace(Web.base_url(), "https://", "") user = user.nickname api = Keyword.get(@suggestions, :third_party_engine, "") url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) + with {:ok, %{status_code: 200, body: body}} <- - @httpoison.get(url, [], [timeout: 300000, recv_timeout: 300000]), + @httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), {:ok, data} <- Jason.decode(body) do - data2 = Enum.slice(data, 0, 40) |> Enum.map(fn(x) -> - Map.put(x, "id", User.get_or_fetch(x["acct"]).id) - end) + data2 = + Enum.slice(data, 0, 40) + |> Enum.map(fn x -> + Map.put(x, "id", User.get_or_fetch(x["acct"]).id) + end) + conn |> json(data2) else From df3233e7e798563afe4b5a937b0bdd13e101973b Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 13:20:58 +0900 Subject: [PATCH 09/17] improve getting host name --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e397b911d..2f8139fe6 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1076,7 +1076,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @suggestions Application.get_env(:pleroma, :suggestions) def suggestions(%{assigns: %{user: user}} = conn, _) do - host = String.replace(Web.base_url(), "https://", "") + host = + Application.get_env(:pleroma, Pleroma.Web.Endpoint) + |> Keyword.get(:url) + |> Keyword.get(:host) + user = user.nickname api = Keyword.get(@suggestions, :third_party_engine, "") url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) From d76f0d87bebd655bcbc4259a47a4ee8fd4f00887 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 16:45:18 +0900 Subject: [PATCH 10/17] do nothing if configuration is skipped --- config/config.exs | 6 +-- .../mastodon_api/mastodon_api_controller.ex | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/config/config.exs b/config/config.exs index 3583e7b46..4d5a7564a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -95,9 +95,9 @@ config :pleroma, :gopher, ip: {0, 0, 0, 0}, port: 9999 -config :pleroma, :suggestions, - third_party_engine: - "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" +# config :pleroma, :suggestions, +# third_party_engine: +# "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 2f8139fe6..ac8f794e9 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1076,28 +1076,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @suggestions Application.get_env(:pleroma, :suggestions) def suggestions(%{assigns: %{user: user}} = conn, _) do - host = - Application.get_env(:pleroma, Pleroma.Web.Endpoint) - |> Keyword.get(:url) - |> Keyword.get(:host) + api = Keyword.get(@suggestions, :third_party_engine, false) - user = user.nickname - api = Keyword.get(@suggestions, :third_party_engine, "") - url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) + if api do + host = + Application.get_env(:pleroma, Pleroma.Web.Endpoint) + |> Keyword.get(:url) + |> Keyword.get(:host) - with {:ok, %{status_code: 200, body: body}} <- - @httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), - {:ok, data} <- Jason.decode(body) do - data2 = - Enum.slice(data, 0, 40) - |> Enum.map(fn x -> - Map.put(x, "id", User.get_or_fetch(x["acct"]).id) - end) + user = user.nickname + url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) - conn - |> json(data2) + with {:ok, %{status_code: 200, body: body}} <- + @httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), + {:ok, data} <- Jason.decode(body) do + data2 = + Enum.slice(data, 0, 40) + |> Enum.map(fn x -> + Map.put(x, "id", User.get_or_fetch(x["acct"]).id) + end) + + conn + |> json(data2) + else + e -> Logger.error("Could not decode user at fetch #{url}, #{inspect(e)}") + end else - e -> Logger.error("Could not decode user at fetch #{url}, #{inspect(e)}") + json(conn, []) end end end From 2b7b1b3e6b276e1db7e610d46298f74a0f0c70f1 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 16:56:30 +0900 Subject: [PATCH 11/17] add suggestionsThirdPartyEngine into /nodeinfo/2.0.json --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 12aca4a10..77401c554 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -21,6 +21,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do def nodeinfo(conn, %{"version" => "2.0"}) do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) + suggestions = Application.get_env(:pleroma, :suggestions) stats = Stats.get_stats() response = %{ @@ -43,7 +44,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do }, metadata: %{ nodeName: Keyword.get(instance, :name), - mediaProxy: Keyword.get(media_proxy, :enabled) + mediaProxy: Keyword.get(media_proxy, :enabled), + suggestionsThirdPartyEngine: Keyword.get(@suggestions, :third_party_engine, false) } } From 8ff336e02a5a4861ba856b3d10e57cb44f1f3a45 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 17:00:14 +0900 Subject: [PATCH 12/17] debug --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 77401c554..5f7d6e86e 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -45,7 +45,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do metadata: %{ nodeName: Keyword.get(instance, :name), mediaProxy: Keyword.get(media_proxy, :enabled), - suggestionsThirdPartyEngine: Keyword.get(@suggestions, :third_party_engine, false) + suggestionsThirdPartyEngine: Keyword.get(suggestions, :third_party_engine, false) } } From 091b7925d39110d2ade4e1db9105a3404dc91da1 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 17:20:13 +0900 Subject: [PATCH 13/17] debug --- config/config.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.exs b/config/config.exs index 4d5a7564a..baaf43c7c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -95,6 +95,7 @@ config :pleroma, :gopher, ip: {0, 0, 0, 0}, port: 9999 +config :pleroma, :suggestions, third_party_engine: false # config :pleroma, :suggestions, # third_party_engine: # "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" From 5b4a21317de6a32001699b33964c7eaeb4f0bec8 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Tue, 17 Jul 2018 17:29:18 +0900 Subject: [PATCH 14/17] correct error message --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ac8f794e9..2ad6521cc 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1099,7 +1099,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> json(data2) else - e -> Logger.error("Could not decode user at fetch #{url}, #{inspect(e)}") + e -> Logger.error("Could not retrieve suggestions at fetch #{url}, #{inspect(e)}") end else json(conn, []) From e4dd58307a692aaa503fccc9cdf9ebae61293f6f Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Wed, 18 Jul 2018 09:58:59 +0900 Subject: [PATCH 15/17] better configuration --- config/config.exs | 8 ++++---- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++-- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/config.exs b/config/config.exs index baaf43c7c..c0a75b786 100644 --- a/config/config.exs +++ b/config/config.exs @@ -95,10 +95,10 @@ config :pleroma, :gopher, ip: {0, 0, 0, 0}, port: 9999 -config :pleroma, :suggestions, third_party_engine: false -# config :pleroma, :suggestions, -# third_party_engine: -# "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" +config :pleroma, :suggestions, + enabled: false, + third_party_engine: + "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 2ad6521cc..5b79f9600 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1076,9 +1076,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @suggestions Application.get_env(:pleroma, :suggestions) def suggestions(%{assigns: %{user: user}} = conn, _) do - api = Keyword.get(@suggestions, :third_party_engine, false) + if Keyword.get(@suggestions, :enabled, false) do + api = Keyword.get(@suggestions, :third_party_engine, false) - if api do host = Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:url) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 5f7d6e86e..e80e63f27 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -45,6 +45,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do metadata: %{ nodeName: Keyword.get(instance, :name), mediaProxy: Keyword.get(media_proxy, :enabled), + suggestions: Keyword.get(suggestions, :enabled, false), suggestionsThirdPartyEngine: Keyword.get(suggestions, :third_party_engine, false) } } From b12d17d2ce270e0d964f599efd4f16fba95b17ce Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Wed, 18 Jul 2018 13:36:20 +0900 Subject: [PATCH 16/17] configurable timeout --- config/config.exs | 3 ++- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 +++-- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/config.exs b/config/config.exs index c0a75b786..8fb7b7c22 100644 --- a/config/config.exs +++ b/config/config.exs @@ -98,7 +98,8 @@ config :pleroma, :gopher, config :pleroma, :suggestions, enabled: false, 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 # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5b79f9600..396f11a70 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1077,7 +1077,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def suggestions(%{assigns: %{user: user}} = conn, _) do if Keyword.get(@suggestions, :enabled, false) do - api = Keyword.get(@suggestions, :third_party_engine, false) + api = Keyword.get(@suggestions, :third_party_engine, "") + timeout = Keyword.get(@suggestions, :timeout, 5000) host = Application.get_env(:pleroma, Pleroma.Web.Endpoint) @@ -1088,7 +1089,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status_code: 200, body: body}} <- - @httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), + @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), {:ok, data} <- Jason.decode(body) do data2 = Enum.slice(data, 0, 40) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index e80e63f27..42d322f89 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -45,8 +45,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do metadata: %{ nodeName: Keyword.get(instance, :name), mediaProxy: Keyword.get(media_proxy, :enabled), - suggestions: Keyword.get(suggestions, :enabled, false), - suggestionsThirdPartyEngine: Keyword.get(suggestions, :third_party_engine, false) + suggestions: %{ + enabled: Keyword.get(suggestions, :enabled, false), + thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""), + timeout: Keyword.get(suggestions, :timeout, 5000) + } } } From f72cfada1ad5cf7ca398ceddf4f70b3b192310ca Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 2 Aug 2018 18:03:35 +0900 Subject: [PATCH 17/17] add suggestions/web config --- config/config.exs | 3 ++- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index 614a3e1fe..aa35f14fb 100644 --- a/config/config.exs +++ b/config/config.exs @@ -113,7 +113,8 @@ config :pleroma, :suggestions, enabled: false, third_party_engine: "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}", - timeout: 300_000 + timeout: 300_000, + web: "https://vinayaka.distsn.org/?{{host}}+{{user}}" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index f9a6d9c25..2fab60274 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -50,7 +50,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do suggestions: %{ enabled: Keyword.get(suggestions, :enabled, false), thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""), - timeout: Keyword.get(suggestions, :timeout, 5000) + timeout: Keyword.get(suggestions, :timeout, 5000), + web: Keyword.get(suggestions, :web, "") } } }