1
0
Fork 0
mirror of https://git.pleroma.social/pleroma/pleroma.git synced 2025-04-12 14:04:08 +00:00

Status: Fill all MastoAPI required values in preview cards

This commit is contained in:
Haelwenn (lanodan) Monnier 2024-02-15 00:57:34 +01:00
parent c7119d17d8
commit 656dce96dc
No known key found for this signature in database
4 changed files with 95 additions and 6 deletions
changelog.d
lib/pleroma/web
api_spec/schemas
mastodon_api/views
test/pleroma/web/mastodon_api/controllers

View file

@ -0,0 +1 @@
Status: Fill all MastoAPI required values in preview cards

View file

@ -34,16 +34,40 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :object,
nullable: true,
description: "Preview card for links included within status content",
required: [:url, :title, :description, :type],
# Yeah, it's effectivelly all required in MastoAPI so far
required: [
:url,
:title,
:description,
:type,
:author_name,
:author_url,
:provider_name,
:provider_url,
:html,
:width,
:height,
:image,
:embed_url,
:blurhash
],
properties: %{
url: %Schema{type: :string, format: :uri, description: "Location of linked resource"},
title: %Schema{type: :string, description: "Title of linked resource"},
description: %Schema{type: :string, description: "Description of preview"},
type: %Schema{
type: :string,
enum: ["link", "photo", "video", "rich"],
description: "The type of the preview card"
},
author_name: %Schema{type: :string, description: "author of the original resource"},
author_url: %Schema{
type: :string,
format: :uri,
description: "link to the author of the original resource"
},
provider_name: %Schema{
type: :string,
nullable: true,
description: "The provider of the original resource"
},
provider_url: %Schema{
@ -51,7 +75,13 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
format: :uri,
description: "A link to the provider of the original resource"
},
url: %Schema{type: :string, format: :uri, description: "Location of linked resource"},
html: %Schema{
type: :string,
format: :html,
description: "HTML to be used for generating the preview card"
},
width: %Schema{type: :integer, description: "Width of preview, in pixels"},
height: %Schema{type: :integer, description: "Height of preview, in pixels"},
image: %Schema{
type: :string,
nullable: true,
@ -62,8 +92,17 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :string,
description: "Alternate text that describes what is in the thumbnail"
},
title: %Schema{type: :string, description: "Title of linked resource"},
description: %Schema{type: :string, description: "Description of preview"}
embed_url: %Schema{
type: :string,
format: :uri,
description: "Used for photo embeds, instead of custom `html`"
},
blurhash: %Schema{
type: :string,
nullable: true,
description:
"A hash computed by the (BlurHash algorithm)[https://github.com/woltapp/blurhash], for generating colorful preview thumbnails when media has not been downloaded yet."
}
}
},
content: %Schema{type: :string, format: :html, description: "HTML-encoded status content"},

View file

@ -586,6 +586,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
image_description: rich_media["image:alt"] || "",
title: rich_media["title"] || "",
description: rich_media["description"] || "",
author_name: "",
author_url: "",
html: "",
width: 0,
height: 0,
embed_url: "",
blurhash: nil,
pleroma: %{
opengraph:
rich_media

View file

@ -1687,7 +1687,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"description" =>
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
}
}
},
"author_name" => "",
"author_url" => "",
"blurhash" => nil,
"embed_url" => "",
"height" => 0,
"html" => "",
"width" => 0
}
response =
@ -1708,6 +1715,41 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert response_two["card"] == card_data
end
test "replaces missing description with an empty string", %{conn: conn, user: user} do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
{:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})
response =
conn
|> get("/api/v1/statuses/#{activity.id}")
|> json_response_and_validate_schema(:ok)
assert response["card"] == %{
"type" => "link",
"title" => "Pleroma",
"description" => "",
"image" => nil,
"provider_name" => "example.com",
"provider_url" => "https://example.com",
"url" => "https://example.com/ogp-missing-data",
"pleroma" => %{
"opengraph" => %{
"title" => "Pleroma",
"type" => "website",
"url" => "https://example.com/ogp-missing-data"
}
},
"author_name" => "",
"author_url" => "",
"blurhash" => nil,
"embed_url" => "",
"height" => 0,
"html" => "",
"width" => 0
}
end
end
test "bookmarks" do