MastoAPI Attachment: Use "summary" for descriptions if present
This commit is contained in:
parent
2ae1b802f2
commit
197647a04e
@ -50,7 +50,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Attachment do
|
||||
pleroma: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
mime_type: %Schema{type: :string, description: "mime type of the attachment"}
|
||||
mime_type: %Schema{type: :string, description: "mime type of the attachment"},
|
||||
name: %Schema{
|
||||
type: :string,
|
||||
description: "Name of the attachment, typically the filename"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -571,6 +571,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||
to_string(attachment["id"] || hash_id)
|
||||
end
|
||||
|
||||
description =
|
||||
if attachment["summary"] do
|
||||
HTML.strip_tags(attachment["summary"])
|
||||
else
|
||||
attachment["name"]
|
||||
end
|
||||
|
||||
name = if attachment["summary"], do: attachment["name"]
|
||||
|
||||
pleroma =
|
||||
%{mime_type: media_type}
|
||||
|> Maps.put_if_present(:name, name)
|
||||
|
||||
%{
|
||||
id: attachment_id,
|
||||
url: href,
|
||||
@ -578,8 +591,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||
preview_url: href_preview,
|
||||
text_url: href,
|
||||
type: type,
|
||||
description: attachment["name"],
|
||||
pleroma: %{mime_type: media_type},
|
||||
description: description,
|
||||
pleroma: pleroma,
|
||||
blurhash: attachment["blurhash"]
|
||||
}
|
||||
|> Maps.put_if_present(:meta, meta)
|
||||
|
@ -456,45 +456,78 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||
assert mention.url == recipient.ap_id
|
||||
end
|
||||
|
||||
test "attachments" do
|
||||
object = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "someurl",
|
||||
"width" => 200,
|
||||
"height" => 100
|
||||
}
|
||||
],
|
||||
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
|
||||
"uuid" => 6
|
||||
}
|
||||
describe "attachments" do
|
||||
test "Complete Mastodon style" do
|
||||
object = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "someurl",
|
||||
"width" => 200,
|
||||
"height" => 100
|
||||
}
|
||||
],
|
||||
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
|
||||
"uuid" => 6
|
||||
}
|
||||
|
||||
expected = %{
|
||||
id: "1638338801",
|
||||
type: "image",
|
||||
url: "someurl",
|
||||
remote_url: "someurl",
|
||||
preview_url: "someurl",
|
||||
text_url: "someurl",
|
||||
description: nil,
|
||||
pleroma: %{mime_type: "image/png"},
|
||||
meta: %{original: %{width: 200, height: 100, aspect: 2}},
|
||||
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
||||
}
|
||||
expected = %{
|
||||
id: "1638338801",
|
||||
type: "image",
|
||||
url: "someurl",
|
||||
remote_url: "someurl",
|
||||
preview_url: "someurl",
|
||||
text_url: "someurl",
|
||||
description: nil,
|
||||
pleroma: %{mime_type: "image/png"},
|
||||
meta: %{original: %{width: 200, height: 100, aspect: 2}},
|
||||
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
||||
}
|
||||
|
||||
api_spec = Pleroma.Web.ApiSpec.spec()
|
||||
api_spec = Pleroma.Web.ApiSpec.spec()
|
||||
|
||||
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
||||
assert_schema(expected, "Attachment", api_spec)
|
||||
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
||||
assert_schema(expected, "Attachment", api_spec)
|
||||
|
||||
# If theres a "id", use that instead of the generated one
|
||||
object = Map.put(object, "id", 2)
|
||||
result = StatusView.render("attachment.json", %{attachment: object})
|
||||
# If theres a "id", use that instead of the generated one
|
||||
object = Map.put(object, "id", 2)
|
||||
result = StatusView.render("attachment.json", %{attachment: object})
|
||||
|
||||
assert %{id: "2"} = result
|
||||
assert_schema(result, "Attachment", api_spec)
|
||||
assert %{id: "2"} = result
|
||||
assert_schema(result, "Attachment", api_spec)
|
||||
end
|
||||
|
||||
test "Honkerific" do
|
||||
object = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "someurl"
|
||||
}
|
||||
],
|
||||
"name" => "fool.jpeg",
|
||||
"summary" => "they have played us for absolute fools."
|
||||
}
|
||||
|
||||
expected = %{
|
||||
blurhash: nil,
|
||||
description: "they have played us for absolute fools.",
|
||||
id: "1638338801",
|
||||
pleroma: %{mime_type: "image/png", name: "fool.jpeg"},
|
||||
preview_url: "someurl",
|
||||
remote_url: "someurl",
|
||||
text_url: "someurl",
|
||||
type: "image",
|
||||
url: "someurl"
|
||||
}
|
||||
|
||||
api_spec = Pleroma.Web.ApiSpec.spec()
|
||||
|
||||
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
||||
assert_schema(expected, "Attachment", api_spec)
|
||||
end
|
||||
end
|
||||
|
||||
test "put the url advertised in the Activity in to the url attribute" do
|
||||
|
Loading…
Reference in New Issue
Block a user