FEATURE: Onebox and Download for WEBP and AVIF (#23235)

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
This commit is contained in:
Rafael dos Santos Silva 2023-08-24 16:44:06 -03:00 committed by GitHub
parent 59569a6e64
commit d10e9a6c1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -5,8 +5,8 @@ module Onebox
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)

View File

@ -39,6 +39,18 @@ RSpec.describe Onebox::Engine::ImageOnebox do
).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(