diff --git a/app/assets/javascripts/discourse/app/lib/uploads.js b/app/assets/javascripts/discourse/app/lib/uploads.js index 95dbeba100b..a31095572e9 100644 --- a/app/assets/javascripts/discourse/app/lib/uploads.js +++ b/app/assets/javascripts/discourse/app/lib/uploads.js @@ -196,7 +196,7 @@ export function authorizedExtensions(staff, siteSettings) { function authorizedImagesExtensions(staff, siteSettings) { return authorizesAllExtensions(staff, siteSettings) - ? "png, jpg, jpeg, gif, svg, ico, heic, heif, webp" + ? "png, jpg, jpeg, gif, svg, ico, heic, heif, webp, avif" : imagesExtensions(staff, siteSettings).join(", "); } @@ -230,7 +230,7 @@ export function authorizesOneOrMoreImageExtensions(staff, siteSettings) { } export function isImage(path) { - return /\.(png|webp|jpe?g|gif|svg|ico|heic|heif)$/i.test(path); + return /\.(png|webp|jpe?g|gif|svg|ico|heic|heif|avif)$/i.test(path); } export function isVideo(path) { diff --git a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js index bede514d279..815e913001b 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js @@ -236,14 +236,16 @@ module("Unit | Utility | uploads", function (hooks) { }); test("isImage", function (assert) { - ["png", "webp", "jpg", "jpeg", "gif", "ico"].forEach((extension) => { - let image = "image." + extension; - assert.ok(isImage(image), image + " is recognized as an image"); - assert.ok( - isImage("http://foo.bar/path/to/" + image), - image + " is recognized as an image" - ); - }); + ["png", "webp", "jpg", "jpeg", "gif", "ico", "avif"].forEach( + (extension) => { + let image = "image." + extension; + assert.ok(isImage(image), image + " is recognized as an image"); + assert.ok( + isImage("http://foo.bar/path/to/" + image), + image + " is recognized as an image" + ); + } + ); assert.notOk(isImage("file.txt")); assert.notOk(isImage("http://foo.bar/path/to/file.txt")); assert.notOk(isImage("")); diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 25dd5b860a0..ec1827e36c6 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -175,7 +175,7 @@ class OptimizedImage < ActiveRecord::Base paths.each { |path| raise Discourse::InvalidAccess unless safe_path?(path) } end - IM_DECODERS ||= /\A(jpe?g|png|ico|gif|webp)\z/i + IM_DECODERS ||= /\A(jpe?g|png|ico|gif|webp|avif)\z/i def self.prepend_decoder!(path, ext_path = nil, opts = nil) opts ||= {} diff --git a/config/nginx.sample.conf b/config/nginx.sample.conf index c1a327fb76d..98a4b2dbbcc 100644 --- a/config/nginx.sample.conf +++ b/config/nginx.sample.conf @@ -203,7 +203,7 @@ server { try_files $uri =404; } # this allows us to bypass rails - location ~* \.(gif|png|jpg|jpeg|bmp|tif|tiff|ico|webp)$ { + location ~* \.(gif|png|jpg|jpeg|bmp|tif|tiff|ico||avif)$ { add_header Access-Control-Allow-Origin *; try_files $uri =404; } diff --git a/config/site_settings.yml b/config/site_settings.yml index 51f8bb2cdb7..98ff694b03c 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1352,12 +1352,12 @@ files: default: 50000 max: 1024000 theme_authorized_extensions: - default: "wasm|jpg|jpeg|png|woff|woff2|svg|eot|ttf|otf|gif|webp|js" + default: "wasm|jpg|jpeg|png|woff|woff2|svg|eot|ttf|otf|gif|webp|avif|js" type: list list_type: compact authorized_extensions: client: true - default: "jpg|jpeg|png|gif|heic|heif|webp" + default: "jpg|jpeg|png|gif|heic|heif|webp|avif" refresh: true type: list list_type: compact diff --git a/lib/file_helper.rb b/lib/file_helper.rb index aeab06d2900..229705fdd70 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -158,7 +158,7 @@ class FileHelper end def self.supported_images - @@supported_images ||= Set.new %w[jpg jpeg png gif svg ico webp] + @@supported_images ||= Set.new %w[jpg jpeg png gif svg ico webp avif] end def self.inline_images diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index 25d0284e2df..61ee801420a 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -662,7 +662,7 @@ class UploadCreator if is_animated != nil # FastImage will return nil if it cannot determine if animated is_animated - elsif type == "gif" || type == "webp" + elsif %w[gif webp avif].include?(type) # Only GIFs, WEBPs and a few other unsupported image types can be animated OptimizedImage.ensure_safe_paths!(@file.path)