Merge remote-tracking branch 'origin/develop' into upgrade-hackney

This commit is contained in:
Alex Gleason 2021-12-08 09:54:57 -06:00
commit e4f1f1012f
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 81 additions and 7 deletions

View file

@ -68,12 +68,14 @@ def fix_media_type(data) do
end
end
defp handle_href(href, mediaType) do
defp handle_href(href, mediaType, data) do
[
%{
"href" => href,
"type" => "Link",
"mediaType" => mediaType
"mediaType" => mediaType,
"width" => data["width"],
"height" => data["height"]
}
]
end
@ -81,10 +83,10 @@ defp handle_href(href, mediaType) do
defp fix_url(data) do
cond do
is_binary(data["url"]) ->
Map.put(data, "url", handle_href(data["url"], data["mediaType"]))
Map.put(data, "url", handle_href(data["url"], data["mediaType"], data))
is_binary(data["href"]) and data["url"] == nil ->
Map.put(data, "url", handle_href(data["href"], data["mediaType"]))
Map.put(data, "url", handle_href(data["href"], data["mediaType"], data))
true ->
data

View file

@ -105,5 +105,37 @@ test "it handles image dimensions" do
assert attachment.mediaType == "image/jpeg"
end
test "it transforms image dimentions to our internal format" do
attachment = %{
"type" => "Document",
"name" => "Hello world",
"url" => "https://media.example.tld/1.jpg",
"width" => 880,
"height" => 960,
"mediaType" => "image/jpeg",
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
}
expected = %AttachmentValidator{
type: "Document",
name: "Hello world",
mediaType: "image/jpeg",
blurhash: "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of",
url: [
%AttachmentValidator.UrlObjectValidator{
type: "Link",
mediaType: "image/jpeg",
href: "https://media.example.tld/1.jpg",
width: 880,
height: 960
}
]
}
{:ok, ^expected} =
AttachmentValidator.cast_and_validate(attachment)
|> Ecto.Changeset.apply_action(:insert)
end
end
end

View file

@ -61,7 +61,7 @@ test "it remaps video URLs as attachments if necessary" do
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
"mediaType" => "video/mp4",
"type" => "Link",
"width" => nil,
"width" => 480,
"height" => nil
}
]
@ -87,7 +87,7 @@ test "it remaps video URLs as attachments if necessary" do
"mediaType" => "video/mp4",
"type" => "Link",
"width" => nil,
"height" => nil
"height" => 1080
}
]
}
@ -119,7 +119,7 @@ test "it works for peertube videos with only their mpegURL map" do
"mediaType" => "video/mp4",
"type" => "Link",
"width" => nil,
"height" => nil
"height" => 1080
}
]
}

View file

@ -524,4 +524,44 @@ test "returns {:ok, %Object{}} for success case" do
)
end
end
describe "fix_attachments/1" do
test "transforms dimensions into a url" do
object = %{
"attachment" => [
%{
"type" => "Document",
"name" => "Hello world",
"url" => "https://media.example.tld/1.jpg",
"width" => 880,
"height" => 960,
"mediaType" => "image/jpeg",
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
}
]
}
expected = %{
"attachment" => [
%{
"type" => "Document",
"name" => "Hello world",
"url" => [
%{
"type" => "Link",
"mediaType" => "image/jpeg",
"href" => "https://media.example.tld/1.jpg",
"width" => 880,
"height" => 960
}
],
"mediaType" => "image/jpeg",
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
}
]
}
assert Transmogrifier.fix_attachments(object) == expected
end
end
end