mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-05-20 02:28:07 +00:00
Compare commits
7 commits
ba34e0983d
...
2d1d5dfd6e
Author | SHA1 | Date | |
---|---|---|---|
2d1d5dfd6e | |||
50af909c01 | |||
6f6bede900 | |||
87b8ac3ce6 | |||
a299ddb10e | |||
acfded5ae8 | |||
e72fd4ceb6 |
1
changelog.d/card-image-description.add
Normal file
1
changelog.d/card-image-description.add
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Include image description in status media cards
|
1
changelog.d/receiverworker-error-handling.fix
Normal file
1
changelog.d/receiverworker-error-handling.fix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ReceiverWorker: Make sure non-{:ok, _} is returned as {:error, …}
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF do
|
defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
require Logger
|
require Logger
|
||||||
|
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
|
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
|
||||||
|
|
||||||
|
@ -158,7 +159,20 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
|
|
||||||
@spec instance_list_from_tuples([{String.t(), String.t()}]) :: [String.t()]
|
@spec instance_list_from_tuples([{String.t(), String.t()}]) :: [String.t()]
|
||||||
def instance_list_from_tuples(list) do
|
def instance_list_from_tuples(list) do
|
||||||
Enum.map(list, fn {instance, _} -> instance end)
|
Enum.map(list, fn
|
||||||
|
{instance, _} -> instance
|
||||||
|
instance when is_binary(instance) -> instance
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec normalize_instance_list(list()) :: [{String.t(), String.t()}]
|
||||||
|
def normalize_instance_list(list) do
|
||||||
|
Enum.map(list, fn
|
||||||
|
{host, reason} when not_empty_string(host) and not_empty_string(reason) -> {host, reason}
|
||||||
|
{host, _reason} when not_empty_string(host) -> {host, ""}
|
||||||
|
host when not_empty_string(host) -> {host, ""}
|
||||||
|
value -> raise "Invalid MRF config: #{inspect(value)}"
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def describe(policies) do
|
def describe(policies) do
|
||||||
|
|
|
@ -264,13 +264,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
mrf_simple_excluded =
|
mrf_simple_excluded =
|
||||||
Config.get(:mrf_simple)
|
Config.get(:mrf_simple)
|
||||||
|> Enum.map(fn {rule, instances} ->
|
|> Enum.map(fn {rule, instances} ->
|
||||||
|
instances = MRF.normalize_instance_list(instances)
|
||||||
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
|
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mrf_simple =
|
mrf_simple =
|
||||||
mrf_simple_excluded
|
mrf_simple_excluded
|
||||||
|> Enum.map(fn {rule, instances} ->
|
|> Enum.map(fn {rule, instances} ->
|
||||||
{rule, Enum.map(instances, fn {host, _} -> host end)}
|
{rule, MRF.instance_list_from_tuples(instances)}
|
||||||
end)
|
end)
|
||||||
|> Map.new()
|
|> Map.new()
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
||||||
format: :uri,
|
format: :uri,
|
||||||
description: "Preview thumbnail"
|
description: "Preview thumbnail"
|
||||||
},
|
},
|
||||||
|
image_description: %Schema{
|
||||||
|
type: :string,
|
||||||
|
description: "Alternate text that describes what is in the thumbnail"
|
||||||
|
},
|
||||||
title: %Schema{type: :string, description: "Title of linked resource"},
|
title: %Schema{type: :string, description: "Title of linked resource"},
|
||||||
description: %Schema{type: :string, description: "Description of preview"}
|
description: %Schema{type: :string, description: "Description of preview"}
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,6 +589,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
|
provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
|
||||||
url: page_url,
|
url: page_url,
|
||||||
image: image_url,
|
image: image_url,
|
||||||
|
image_description: rich_media["image:alt"] || "",
|
||||||
title: rich_media["title"] || "",
|
title: rich_media["title"] || "",
|
||||||
description: rich_media["description"] || "",
|
description: rich_media["description"] || "",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
|
|
|
@ -52,7 +52,8 @@ defmodule Pleroma.Workers.ReceiverWorker do
|
||||||
{:error, {:reject, reason}} -> {:cancel, reason}
|
{:error, {:reject, reason}} -> {:cancel, reason}
|
||||||
{:signature, false} -> {:cancel, :invalid_signature}
|
{:signature, false} -> {:cancel, :invalid_signature}
|
||||||
{:error, {:error, reason = "Object has been deleted"}} -> {:cancel, reason}
|
{:error, {:error, reason = "Object has been deleted"}} -> {:cancel, reason}
|
||||||
e -> e
|
{:error, _} = e -> e
|
||||||
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,11 +81,27 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
|
|
||||||
assert MRF.instance_list_from_tuples(list) == expected
|
assert MRF.instance_list_from_tuples(list) == expected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it handles legacy config" do
|
||||||
|
list = [{"some.tld", "a reason"}, "other.tld"]
|
||||||
|
expected = ["some.tld", "other.tld"]
|
||||||
|
|
||||||
|
assert MRF.instance_list_from_tuples(list) == expected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "normalize_instance_list/1" do
|
||||||
|
test "returns a list of tuples" do
|
||||||
|
list = [{"some.tld", "a reason"}, "other.tld"]
|
||||||
|
expected = [{"some.tld", "a reason"}, {"other.tld", ""}]
|
||||||
|
|
||||||
|
assert MRF.normalize_instance_list(list) == expected
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "describe/0" do
|
describe "describe/0" do
|
||||||
test "it works as expected with noop policy" do
|
test "it works as expected with noop policy" do
|
||||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
clear_config([:mrf, :policies], [MRF.NoOpPolicy])
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
|
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
|
||||||
|
@ -116,6 +132,32 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
|
|
||||||
{:ok, ^expected} = MRF.describe()
|
{:ok, ^expected} = MRF.describe()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works as expected with SimplePolicy" do
|
||||||
|
clear_config([:mrf, :policies], [MRF.SimplePolicy])
|
||||||
|
clear_config([:mrf_simple, :reject], [{"lain.com", "2kool4skool"}, "othersite.xyz"])
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
exclusions: false,
|
||||||
|
mrf_hashtag: %{federated_timeline_removal: [], reject: [], sensitive: ["nsfw"]},
|
||||||
|
mrf_policies: ["SimplePolicy", "HashtagPolicy"],
|
||||||
|
mrf_simple: %{
|
||||||
|
accept: [],
|
||||||
|
avatar_removal: [],
|
||||||
|
banner_removal: [],
|
||||||
|
federated_timeline_removal: [],
|
||||||
|
followers_only: [],
|
||||||
|
media_nsfw: [],
|
||||||
|
media_removal: [],
|
||||||
|
reject: ["lain.com", "othersite.xyz"],
|
||||||
|
reject_deletes: [],
|
||||||
|
report_removal: []
|
||||||
|
},
|
||||||
|
mrf_simple_info: %{reject: %{"lain.com" => %{"reason" => "2kool4skool"}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, ^expected} = MRF.describe()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "config_descriptions/0" do
|
test "config_descriptions/0" do
|
||||||
|
|
|
@ -1717,6 +1717,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
|
|
||||||
card_data = %{
|
card_data = %{
|
||||||
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
||||||
|
"image_description" => "",
|
||||||
"provider_name" => "example.com",
|
"provider_name" => "example.com",
|
||||||
"provider_url" => "https://example.com",
|
"provider_url" => "https://example.com",
|
||||||
"title" => "The Rock",
|
"title" => "The Rock",
|
||||||
|
@ -1770,6 +1771,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
"title" => "Pleroma",
|
"title" => "Pleroma",
|
||||||
"description" => "",
|
"description" => "",
|
||||||
"image" => nil,
|
"image" => nil,
|
||||||
|
"image_description" => "",
|
||||||
"provider_name" => "example.com",
|
"provider_name" => "example.com",
|
||||||
"provider_url" => "https://example.com",
|
"provider_url" => "https://example.com",
|
||||||
"url" => "https://example.com/ogp-missing-data",
|
"url" => "https://example.com/ogp-missing-data",
|
||||||
|
|
|
@ -773,6 +773,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
page_url = "http://example.com"
|
page_url = "http://example.com"
|
||||||
|
|
||||||
card = %{
|
card = %{
|
||||||
|
"image:alt" => "Example image description",
|
||||||
url: page_url,
|
url: page_url,
|
||||||
site_name: "Example site name",
|
site_name: "Example site name",
|
||||||
title: "Example website",
|
title: "Example website",
|
||||||
|
@ -780,7 +781,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
description: "Example description"
|
description: "Example description"
|
||||||
}
|
}
|
||||||
|
|
||||||
%{provider_name: "example.com"} =
|
%{provider_name: "example.com", image_description: "Example image description"} =
|
||||||
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue