UX: Use dominant color while loading onebox images (#21091)

When we "pull hotlinked images" on onebox images, they are added to the uploads table and their dominant color is calculated. This commit adds the data to the HTML so that it can be used by the client in the same way as non-onebox images. It also adds specific handling to the new `discourse-lazy-videos` plugin.
This commit is contained in:
David Taylor
2023-04-13 12:04:46 +01:00
committed by GitHub
parent 18c81958e5
commit e52f322cb5
6 changed files with 30 additions and 6 deletions

View File

@ -1080,7 +1080,7 @@ RSpec.describe CookedPostProcessor do
.returns("<img class='onebox' src='#{image_url}' />")
post = Fabricate(:post, raw: url)
upload.update!(url: "https://test.s3.amazonaws.com/something.png")
upload.update!(url: "https://test.s3.amazonaws.com/something.png", dominant_color: "00ffff")
PostHotlinkedMedia.create!(
url: "//image.com/avatar.png",
@ -1094,7 +1094,7 @@ RSpec.describe CookedPostProcessor do
cpp.post_process_oneboxes
expect(cpp.doc.to_s).to eq(
"<p><img class=\"onebox\" src=\"#{upload.url}\" width=\"100\" height=\"200\"></p>",
"<p><img class=\"onebox\" src=\"#{upload.url}\" data-dominant-color=\"00ffff\" width=\"100\" height=\"200\"></p>",
)
upload.destroy!
@ -1124,7 +1124,10 @@ RSpec.describe CookedPostProcessor do
.returns("<img class='onebox' src='#{image_url}' />")
post = Fabricate(:post, raw: url)
upload.update!(url: "https://test.s3.amazonaws.com/something.png")
upload.update!(
url: "https://test.s3.amazonaws.com/something.png",
dominant_color: "00ffff",
)
PostHotlinkedMedia.create!(
url: "//image.com/avatar.png",
@ -1141,7 +1144,7 @@ RSpec.describe CookedPostProcessor do
cpp.post_process_oneboxes
expect(cpp.doc.to_s).to eq(
"<p><img class=\"onebox\" src=\"#{cooked_url}\" width=\"100\" height=\"200\"></p>",
"<p><img class=\"onebox\" src=\"#{cooked_url}\" data-dominant-color=\"00ffff\" width=\"100\" height=\"200\"></p>",
)
end
end