fix(feed): tighten enclosure metadata

This commit is contained in:
Lain Soykaf 2026-07-24 20:59:13 +04:00
commit 5f71532442
No known key found for this signature in database
7 changed files with 35 additions and 19 deletions

View file

@ -131,7 +131,7 @@ defmodule Pleroma.Web.Feed.FeedView do
end
attachments_html =
if data["sensitive"] do
if sensitive?(data) do
""
else
(data["attachment"] || [])
@ -181,6 +181,8 @@ defmodule Pleroma.Web.Feed.FeedView do
def activity_context(activity), do: escape(activity.data["context"])
def sensitive?(data), do: data["sensitive"] in [true, "true"]
def feed_self_url(conn) do
conn
|> Phoenix.Controller.current_url()
@ -237,15 +239,15 @@ defmodule Pleroma.Web.Feed.FeedView do
end
end
def attachment_previewable?(attachment) do
attachment_medium(attachment) in ["image", "video", "audio"]
def rss_enclosure_attachment(attachments) do
Enum.find(attachments || [], &(not is_nil(attachment_size_positive(&1))))
end
def attachment_description(attachment) do
attachment["name"] || ""
end
def media_content_xml(_attachment, true), do: ""
def media_content_xml(_attachment, sensitive) when sensitive in [true, "true"], do: ""
def media_content_xml(attachment, _sensitive) do
href = escape(attachment_href(attachment) || "")

View file

@ -21,7 +21,7 @@
<category term="<%= tag %>"></category>
<% end %>
<%= unless @data["sensitive"] do %>
<%= unless sensitive?(@data) do %>
<%= for attachment <- @data["attachment"] || [] do %>
<%= if size = attachment_size_positive(attachment) do %>
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size %>"/>

View file

@ -18,15 +18,14 @@
<% end %>
<% end %>
<%= unless @data["sensitive"] do %>
<%= with [attachment | _] <- @data["attachment"] || [] do %>
<%= size = attachment_size_positive(attachment) %>
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size || 0 %>" />
<%= unless sensitive?(@data) do %>
<%= with attachment when not is_nil(attachment) <- rss_enclosure_attachment(@data["attachment"]) do %>
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= attachment_size_positive(attachment) %>" />
<% end %>
<% end %>
<%= for attachment <- @data["attachment"] || [] do %>
<%= media_content_xml(attachment, @data["sensitive"]) %>
<%= media_content_xml(attachment, sensitive?(@data)) %>
<% end %>
<%= if @data["inReplyTo"] do %>

View file

@ -24,7 +24,7 @@
<category term="<%= tag %>"></category>
<% end %>
<%= unless @data["sensitive"] do %>
<%= unless sensitive?(@data) do %>
<%= for attachment <- @data["attachment"] || [] do %>
<%= if size = attachment_size_positive(attachment) do %>
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size %>"/>

View file

@ -6,15 +6,14 @@
<description><%= activity_description(@data) %></description>
<content:encoded><![CDATA[<%= rss_content_encoded(@data) %>]]></content:encoded>
<%= unless @data["sensitive"] do %>
<%= with [attachment | _] <- @data["attachment"] || [] do %>
<%= size = attachment_size_positive(attachment) %>
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size || 0 %>"/>
<%= unless sensitive?(@data) do %>
<%= with attachment when not is_nil(attachment) <- rss_enclosure_attachment(@data["attachment"]) do %>
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= attachment_size_positive(attachment) %>"/>
<% end %>
<% end %>
<%= for attachment <- @data["attachment"] || [] do %>
<%= media_content_xml(attachment, @data["sensitive"]) %>
<%= media_content_xml(attachment, sensitive?(@data)) %>
<% end %>
<%= for tag <- Pleroma.Object.hashtags(@object) do %>