Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85828541
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/web/metadata/instance.ex b/lib/pleroma/web/metadata/instance.ex
index 78e166b74..5b75c3cbd 100644
--- a/lib/pleroma/web/metadata/instance.ex
+++ b/lib/pleroma/web/metadata/instance.ex
@@ -1,75 +1,73 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.Instance do
alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.MastodonAPI.InstanceView
alias Pleroma.Web.Nodeinfo.Nodeinfo
@behaviour Provider
@impl Provider
def build_tags(_params) do
[]
|> build_info_tag()
|> build_panel_tag()
|> build_nodeinfo_tag()
end
+ def build_info_tag(acc \\ []) do
+ "show.json"
+ |> InstanceView.render(%{})
+ |> Jason.encode!()
+ |> check_for_empty()
+ |> case do
+ "" ->
+ acc
+
+ safe_data ->
+ [make_tag("instance:info", safe_data) | acc]
+ end
+ end
+
def build_panel_tag(acc \\ []) do
- instance_path =
- Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
- |> IO.inspect()
+ instance_path = Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
if File.exists?(instance_path) do
instance_path
|> File.read!()
|> case do
"" ->
acc
safe_data ->
[make_tag("instance:panel", safe_data) | acc]
end
else
acc
end
end
- def build_info_tag(acc \\ []) do
- "show.json"
- |> InstanceView.render(%{})
- |> Jason.encode!()
- |> check_for_empty()
- |> case do
- "" ->
- acc
-
- safe_data ->
- [make_tag("instance:info", safe_data) | acc]
- end
- end
-
def build_nodeinfo_tag(acc \\ []) do
case Nodeinfo.get_nodeinfo("2.0") do
{:error, _} ->
acc
nodeinfo_data ->
[make_tag("instance:nodeinfo", Jason.encode!(nodeinfo_data)) | acc]
end
end
defp check_for_empty(data) do
if data != "" and data != "\u200B" do
data
else
""
end
end
defp make_tag(key, data) do
{:meta, [property: key, content: data], []}
end
end
diff --git a/lib/pleroma/web/metadata/user.ex b/lib/pleroma/web/metadata/user.ex
index 1c1398f33..0bfc405dc 100644
--- a/lib/pleroma/web/metadata/user.ex
+++ b/lib/pleroma/web/metadata/user.ex
@@ -1,64 +1,60 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.User do
alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.Metadata.Providers.Provider
@behaviour Provider
@impl Provider
def build_tags(params) do
- IO.inspect(params, label: "the build tag _params")
-
[]
|> build_accounts_tag(params)
|> build_relationships_tag(params)
end
def build_accounts_tag(acc \\ [], %{user: user}) do
- IO.inspect(user.id, label: "the user id")
-
"show.json"
|> AccountView.render(%{user: user, for: user})
|> Jason.encode!()
|> check_for_empty()
|> case do
"" ->
acc
safe_data ->
[make_tag("user:account", safe_data) | acc]
end
end
def build_relationships_tag(acc \\ [], %{user: %{id: user_id} = user}) do
targets = User.get_all_by_ids(List.wrap(user_id))
"relationships.json"
|> AccountView.render(%{user: user, targets: targets})
|> Jason.encode!()
|> check_for_empty()
|> case do
"" ->
acc
safe_data ->
[make_tag("user:relationships", safe_data) | acc]
end
end
defp check_for_empty(data) do
if data != "" and data != "\u200B" do
data
else
""
end
end
defp make_tag(key, data) do
{:meta, [property: key, content: data], []}
end
end
diff --git a/test/web/metadata/instance_test.exs b/test/web/metadata/instance_test.exs
new file mode 100644
index 000000000..a12c92fae
--- /dev/null
+++ b/test/web/metadata/instance_test.exs
@@ -0,0 +1,81 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Metadata.Providers.InstanceTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.Metadata.Providers.Instance
+
+ setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
+
+ test "it renders the info" do
+ result = Instance.build_tags(%{})
+
+ %{
+ "description" => description,
+ "email" => "admin@example.com",
+ "registrations" => true
+ } =
+ case Enum.find(result, nil, &find_tag(&1, "instance:info")) do
+ nil ->
+ %{}
+
+ {:meta, properties, []} ->
+ properties
+ |> Keyword.get(:content, "")
+ |> Jason.decode!()
+ end
+
+ assert String.equivalent?(description, "A Pleroma instance, an alternative fediverse server")
+ end
+
+ test "it renders the panel" do
+ result = Instance.build_tags(%{})
+
+ html_panel =
+ case Enum.find(result, nil, &find_tag(&1, "instance:panel")) do
+ nil ->
+ %{}
+
+ {:meta, properties, []} ->
+ properties
+ |> Keyword.get(:content, "")
+ end
+
+ assert String.contains?(
+ html_panel,
+ "<p>Welcome to <a href=\"https://pleroma.social\" target=\"_blank\">Pleroma!</a></p>"
+ )
+ end
+
+ test "it renders the node_info" do
+ result = Instance.build_tags(%{})
+
+ %{
+ "metadata" => metadata,
+ "version" => "2.0"
+ } =
+ case Enum.find(result, nil, &find_tag(&1, "instance:nodeinfo")) do
+ nil ->
+ %{}
+
+ {:meta, properties, []} ->
+ properties
+ |> Keyword.get(:content, "")
+ |> Jason.decode!()
+ end
+
+ assert metadata["private"] == false
+ assert metadata["suggestions"] == %{"enabled" => false}
+ end
+
+ def find_tag(tag, property) do
+ with {:meta, properties, []} <- tag,
+ prop_name <- Keyword.get(properties, :property, false) do
+ String.equivalent?(prop_name, property)
+ else
+ _ ->
+ false
+ end
+ end
+end
diff --git a/test/web/metadata/user_test.exs b/test/web/metadata/user_test.exs
new file mode 100644
index 000000000..fde066b1b
--- /dev/null
+++ b/test/web/metadata/user_test.exs
@@ -0,0 +1,64 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Metadata.Providers.UserTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Web.Metadata.Providers.User
+
+ setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
+
+ test "it renders the accounts" do
+ user = insert(:user)
+
+ result = User.build_tags(%{user: user})
+
+ %{"acct" => username, "username" => username} =
+ case Enum.find(result, nil, &find_tag(&1, "user:account")) do
+ {:meta, properties, []} ->
+ get_decoded_content(properties)
+
+ _ ->
+ %{}
+ end
+ end
+
+ test "it renders the relationships" do
+ user = insert(:user)
+
+ result = User.build_tags(%{user: user})
+
+ [
+ %{
+ "blocked_by" => false,
+ "blocking" => false,
+ "showing_reblogs" => true,
+ "subscribing" => false
+ }
+ ] =
+ case Enum.find(result, nil, &find_tag(&1, "user:relationships")) do
+ {:meta, properties, []} ->
+ get_decoded_content(properties)
+
+ _ ->
+ %{}
+ end
+ end
+
+ defp get_decoded_content(props) do
+ props
+ |> Keyword.get(:content, "")
+ |> Jason.decode!()
+ end
+
+ defp find_tag(tag, property) do
+ with {:meta, properties, []} <- tag,
+ prop_name <- Keyword.get(properties, :property, false) do
+ String.equivalent?(prop_name, property)
+ else
+ _ ->
+ false
+ end
+ end
+end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 31, 8:17 AM (19 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1801185
Default Alt Text
(7 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline