Get the nodeinfo address from the well-known
authorEkaterina Vaartis <vaartis@cock.li>
Wed, 18 Sep 2019 16:48:25 +0000 (19:48 +0300)
committerEkaterina Vaartis <vaartis@cock.li>
Wed, 18 Sep 2019 21:16:34 +0000 (00:16 +0300)
lib/pleroma/web/pleroma_api/emoji_api_controller.ex
test/web/emoji_api_controller_test.exs

index 391c317e7197c302574c35d5a6dfdd34ebcf8b6d..6beca426ace1438ccb8f1664948eec50cbd35192 100644 (file)
@@ -148,7 +148,13 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
   """
   def download_from(conn, %{"instance_address" => address, "pack_name" => name} = data) do
     shareable_packs_available =
-      "#{address}/nodeinfo/2.1.json"
+      "#{address}/.well-known/nodeinfo"
+      |> Tesla.get!()
+      |> Map.get(:body)
+      |> Jason.decode!()
+      |> List.last()
+      |> Map.get("href")
+      # Get the actual nodeinfo address and fetch it
       |> Tesla.get!()
       |> Map.get(:body)
       |> Jason.decode!()
index 297dc092f2930315e660bc70b0bd394d9513d142..c5a5536924412e07c34a1cc883eb89bbb70813a1 100644 (file)
@@ -54,9 +54,15 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
     end)
 
     mock(fn
+      %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
+        json([%{href: "https://old-instance/nodeinfo/2.1.json"}])
+
       %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
         json(%{metadata: %{features: []}})
 
+      %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+        json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+
       %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
         json(%{metadata: %{features: ["shareable_emoji_packs"]}})