Skip to content

Commit

Permalink
FEATURE: Onebox and Download for WEBP and AVIF (#23235)
Browse files Browse the repository at this point in the history
This adds support for oneboxing WEBP and AVIF images in posts and fixing
oneboxing fixes download remote images for those formats too.

Reported in https://meta.discourse.org/t/-/276433?u=falco
  • Loading branch information
xfalcox committed Aug 24, 2023
1 parent 59569a6 commit d10e9a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/onebox/engine/image_onebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Engine
class ImageOnebox
include Engine

matches_content_type(%r{^image/(png|jpg|jpeg|gif|bmp|tif|tiff)$})
matches_regexp(%r{^(https?:)?//.+\.(png|jpg|jpeg|gif|bmp|tif|tiff)(\?.*)?$}i)
matches_content_type(%r{^image/(png|jpg|jpeg|gif|bmp|tif|tiff|webp|avif)$})
matches_regexp(%r{^(https?:)?//.+\.(png|jpg|jpeg|gif|bmp|tif|tiff|webp|avif)(\?.*)?$}i)

def always_https?
AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.https_hosts)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/onebox/engine/image_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
).to match(/<img/)
end

it "supports webp" do
expect(Onebox.preview("https://www.gstatic.com/webp/gallery/1.sm.webp").to_s).to match(/<img/)
end

it "supports avif" do
expect(
Onebox.preview(
"https://raw.githubusercontent.com/AOMediaCodec/av1-avif/master/testFiles/Xiph/abandoned_filmgrain.avif",
).to_s,
).to match(/<img/)
end

it "supports image URLs with query parameters" do
expect(
Onebox.preview(
Expand Down

0 comments on commit d10e9a6

Please sign in to comment.