field(:type, :string)
field(:href, ObjectValidators.Uri)
field(:mediaType, :string, default: "application/octet-stream")
+ field(:width, :integer)
+ field(:height, :integer)
end
end
data = fix_media_type(data)
struct
- |> cast(data, [:type, :href, :mediaType])
+ |> cast(data, [:type, :href, :mediaType, :width, :height])
|> validate_inclusion(:type, ["Link"])
|> validate_required([:type, :href, :mediaType])
end
"type" => Map.get(url || %{}, "type", "Link")
}
|> Maps.put_if_present("mediaType", media_type)
+ |> Maps.put_if_present("width", (url || %{})["width"])
+ |> Maps.put_if_present("height", (url || %{})["height"])
%{
"url" => [attachment_url],
assert attachment.mediaType == "image/jpeg"
end
+
+ test "it handles image dimensions" do
+ attachment = %{
+ "url" => [
+ %{
+ "type" => "Link",
+ "mediaType" => "image/jpeg",
+ "href" => "https://example.com/images/1.jpg",
+ "width" => 200,
+ "height" => 100
+ }
+ ],
+ "type" => "Document",
+ "name" => nil,
+ "mediaType" => "image/jpeg"
+ }
+
+ {:ok, attachment} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+
+ assert [
+ %{
+ href: "https://example.com/images/1.jpg",
+ type: "Link",
+ mediaType: "image/jpeg",
+ width: 200,
+ height: 100
+ }
+ ] = attachment.url
+
+ assert attachment.mediaType == "image/jpeg"
+ end
end
end
"href" =>
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
"mediaType" => "audio/ogg",
- "type" => "Link"
+ "type" => "Link",
+ "width" => nil,
+ "height" => nil
}
]
}
"href" =>
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
"mediaType" => "video/mp4",
- "type" => "Link"
+ "type" => "Link",
+ "width" => nil,
+ "height" => nil
}
]
}
"href" =>
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
"mediaType" => "video/mp4",
- "type" => "Link"
+ "type" => "Link",
+ "width" => nil,
+ "height" => nil
}
]
}
"href" =>
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
"mediaType" => "video/mp4",
- "type" => "Link"
+ "type" => "Link",
+ "width" => nil,
+ "height" => nil
}
]
}