mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-26 02:40:18 +00:00
Merge branch 'fix/ogp-missing-data' into 'develop'
Replace missing non-nullable Card attributes with empty strings See merge request pleroma/pleroma!1217
This commit is contained in:
commit
73a7420c23
|
@ -112,6 +112,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
|
- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
|
||||||
- Mastodon API: Exposing default scope of the user to anyone
|
- Mastodon API: Exposing default scope of the user to anyone
|
||||||
- Mastodon API: Make `irreversible` field default to `false` [`POST /api/v1/filters`]
|
- Mastodon API: Make `irreversible` field default to `false` [`POST /api/v1/filters`]
|
||||||
|
- Mastodon API: Replace missing non-nullable Card attributes with empty strings
|
||||||
- User-Agent is now sent correctly for all HTTP requests.
|
- User-Agent is now sent correctly for all HTTP requests.
|
||||||
- MRF: Simple policy now properly delists imported or relayed statuses
|
- MRF: Simple policy now properly delists imported or relayed statuses
|
||||||
|
|
||||||
|
|
|
@ -290,8 +290,8 @@ 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 |> MediaProxy.url(),
|
image: image_url |> MediaProxy.url(),
|
||||||
title: rich_media[:title],
|
title: rich_media[:title] || "",
|
||||||
description: rich_media[:description],
|
description: rich_media[:description] || "",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
opengraph: rich_media
|
opengraph: rich_media
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,10 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
||||||
try do
|
try do
|
||||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
|
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
|
||||||
|
|
||||||
html |> maybe_parse() |> clean_parsed_data() |> check_parsed_data()
|
html
|
||||||
|
|> maybe_parse()
|
||||||
|
|> clean_parsed_data()
|
||||||
|
|> check_parsed_data()
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
{:error, "Parsing error: #{inspect(e)}"}
|
{:error, "Parsing error: #{inspect(e)}"}
|
||||||
|
|
8
test/fixtures/rich_media/ogp-missing-data.html
vendored
Normal file
8
test/fixtures/rich_media/ogp-missing-data.html
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<html prefix="og: http://ogp.me/ns#">
|
||||||
|
<head>
|
||||||
|
<title>Pleroma</title>
|
||||||
|
<meta property="og:title" content="Pleroma" />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://pleroma.social/" />
|
||||||
|
</head>
|
||||||
|
</html>
|
1
test/fixtures/rich_media/ogp.html
vendored
1
test/fixtures/rich_media/ogp.html
vendored
|
@ -5,5 +5,6 @@
|
||||||
<meta property="og:type" content="video.movie" />
|
<meta property="og:type" content="video.movie" />
|
||||||
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
|
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
|
||||||
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
|
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
|
||||||
|
<meta property="og:description" content="Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.">
|
||||||
</head>
|
</head>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -728,6 +728,14 @@ defmodule HttpRequestMock do
|
||||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
|
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("http://example.com/ogp-missing-data", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
def get("http://example.com/malformed", _, _, _) do
|
def get("http://example.com/malformed", _, _, _) do
|
||||||
{:ok,
|
{:ok,
|
||||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
|
||||||
|
|
|
@ -2684,34 +2684,51 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|
||||||
|> json_response(400)
|
|> json_response(400)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "Status rich-media Card", %{conn: conn, user: user} do
|
describe "cards" do
|
||||||
|
setup do
|
||||||
Pleroma.Config.put([:rich_media, :enabled], true)
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
on_exit(fn ->
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
|
end)
|
||||||
|
|
||||||
|
user = insert(:user)
|
||||||
|
%{user: user}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns rich-media card", %{conn: conn, user: user} do
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
|
||||||
|
|
||||||
response =
|
card_data = %{
|
||||||
conn
|
|
||||||
|> get("/api/v1/statuses/#{activity.id}/card")
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
assert response == %{
|
|
||||||
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
||||||
"provider_name" => "www.imdb.com",
|
"provider_name" => "www.imdb.com",
|
||||||
"provider_url" => "http://www.imdb.com",
|
"provider_url" => "http://www.imdb.com",
|
||||||
"title" => "The Rock",
|
"title" => "The Rock",
|
||||||
"type" => "link",
|
"type" => "link",
|
||||||
"url" => "http://www.imdb.com/title/tt0117500/",
|
"url" => "http://www.imdb.com/title/tt0117500/",
|
||||||
"description" => nil,
|
"description" =>
|
||||||
|
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
|
||||||
"pleroma" => %{
|
"pleroma" => %{
|
||||||
"opengraph" => %{
|
"opengraph" => %{
|
||||||
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
||||||
"title" => "The Rock",
|
"title" => "The Rock",
|
||||||
"type" => "video.movie",
|
"type" => "video.movie",
|
||||||
"url" => "http://www.imdb.com/title/tt0117500/"
|
"url" => "http://www.imdb.com/title/tt0117500/",
|
||||||
|
"description" =>
|
||||||
|
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/statuses/#{activity.id}/card")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert response == card_data
|
||||||
|
|
||||||
# works with private posts
|
# works with private posts
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
CommonAPI.post(user, %{"status" => "http://example.com/ogp", "visibility" => "direct"})
|
CommonAPI.post(user, %{"status" => "http://example.com/ogp", "visibility" => "direct"})
|
||||||
|
@ -2722,9 +2739,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
|> get("/api/v1/statuses/#{activity.id}/card")
|
|> get("/api/v1/statuses/#{activity.id}/card")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert response_two == response
|
assert response_two == card_data
|
||||||
|
end
|
||||||
|
|
||||||
Pleroma.Config.put([:rich_media, :enabled], false)
|
test "replaces missing description with an empty string", %{conn: conn, user: user} do
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp-missing-data"})
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/statuses/#{activity.id}/card")
|
||||||
|
|> json_response(:ok)
|
||||||
|
|
||||||
|
assert response == %{
|
||||||
|
"type" => "link",
|
||||||
|
"title" => "Pleroma",
|
||||||
|
"description" => "",
|
||||||
|
"image" => nil,
|
||||||
|
"provider_name" => "pleroma.social",
|
||||||
|
"provider_url" => "https://pleroma.social",
|
||||||
|
"url" => "https://pleroma.social/",
|
||||||
|
"pleroma" => %{
|
||||||
|
"opengraph" => %{
|
||||||
|
"title" => "Pleroma",
|
||||||
|
"type" => "website",
|
||||||
|
"url" => "https://pleroma.social/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
|
||||||
%{
|
%{
|
||||||
image: "http://ia.media-imdb.com/images/rock.jpg",
|
image: "http://ia.media-imdb.com/images/rock.jpg",
|
||||||
title: "The Rock",
|
title: "The Rock",
|
||||||
|
description:
|
||||||
|
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
|
||||||
type: "video.movie",
|
type: "video.movie",
|
||||||
url: "http://www.imdb.com/title/tt0117500/"
|
url: "http://www.imdb.com/title/tt0117500/"
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue