diff --git a/app/assets/stylesheets/views/article.scss b/app/assets/stylesheets/views/article.scss index 9369b3679..7c3c4cf7a 100644 --- a/app/assets/stylesheets/views/article.scss +++ b/app/assets/stylesheets/views/article.scss @@ -35,7 +35,7 @@ aspect-ratio: auto 650 / 273; object-fit: contain; border-radius: var(--radius-auto) var(--radius) 0 0; - max-height: calc(100vh - var(--header-height) - var(--su-4)); + max-height: calc(90vh - var(--header-height)); } } } diff --git a/app/models/article.rb b/app/models/article.rb index 17cdd7b3c..f3c0e8a30 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1011,7 +1011,7 @@ class Article < ApplicationRecord end def enrich_image_attributes - return unless saved_change_to_attribute?(:processed_html) + return unless saved_change_to_attribute?(:processed_html) || saved_change_to_attribute?(:main_image) ::Articles::EnrichImageAttributesWorker.perform_async(id) end diff --git a/app/services/articles/enrich_image_attributes.rb b/app/services/articles/enrich_image_attributes.rb index 990b3faee..d2b8e1587 100644 --- a/app/services/articles/enrich_image_attributes.rb +++ b/app/services/articles/enrich_image_attributes.rb @@ -16,6 +16,7 @@ module Articles ].join(", ").freeze def self.call(article) + fast_image_headers = { "User-Agent" => "#{Settings::Community.community_name} (#{URL.url})" } parsed_html = Nokogiri::HTML.fragment(article.processed_html) main_image_height = default_image_height @@ -35,13 +36,13 @@ module Articles next if image.blank? - img_properties = FastImage.new(image, timeout: 10) + img_properties = FastImage.new(image, timeout: 10, http_header: fast_image_headers) img["width"], img["height"] = img_properties.size img["data-animated"] = true if img_properties.type == :gif end if article.main_image && Settings::UserExperience.cover_image_fit == "limit" - main_image_size = FastImage.size(article.main_image, timeout: 15) + main_image_size = FastImage.size(article.main_image, timeout: 15, http_header: fast_image_headers) main_image_height = (main_image_size[1].to_f / main_image_size[0]) * 1000 if main_image_size end diff --git a/app/services/html/parser.rb b/app/services/html/parser.rb index 5d7d32b39..ee353ee80 100644 --- a/app/services/html/parser.rb +++ b/app/services/html/parser.rb @@ -43,7 +43,8 @@ module Html next if allowed_image_host?(src) if synchronous_detail_detection - img["width"], img["height"] = FastImage.size(src, timeout: 10) + header = { "User-Agent" => "#{Settings::Community.community_name} (#{URL.url})" } + img["width"], img["height"] = FastImage.size(src, timeout: 10, http_header: header) end img["loading"] = "lazy" diff --git a/app/workers/articles/enrich_image_attributes_worker.rb b/app/workers/articles/enrich_image_attributes_worker.rb index 917ec6d20..7b7baf570 100644 --- a/app/workers/articles/enrich_image_attributes_worker.rb +++ b/app/workers/articles/enrich_image_attributes_worker.rb @@ -2,7 +2,7 @@ module Articles class EnrichImageAttributesWorker include Sidekiq::Job - sidekiq_options queue: :medium_priority, retry: 5, lock: :until_executing + sidekiq_options queue: :high_priority, retry: 5, lock: :until_executing def perform(article_id) article = Article.find_by(id: article_id) diff --git a/spec/models/billboard_spec.rb b/spec/models/billboard_spec.rb index bf0b1eab2..50e573baa 100644 --- a/spec/models/billboard_spec.rb +++ b/spec/models/billboard_spec.rb @@ -173,7 +173,8 @@ RSpec.describe Billboard do allow(Images::Optimizer).to receive(:call).and_return(image_url) image_md = "
Hello hey Hey hey
" create(:billboard, body_markdown: image_md, placement_area: "post_comments") - expect(FastImage).to have_received(:size).with(image_url, { timeout: 10 }) + options = { http_header: { "User-Agent" => "DEV(local) (http://forem.test)" }, timeout: 10 } + expect(FastImage).to have_received(:size).with(image_url, options) # width is billboard.prefix_width expect(Images::Optimizer).to have_received(:call).with(image_url, width: Billboard::POST_WIDTH) # Images::Optimizer.call(source, width: width) diff --git a/spec/workers/articles/enrich_image_attributes_worker_spec.rb b/spec/workers/articles/enrich_image_attributes_worker_spec.rb index 54cb64726..0022a2072 100644 --- a/spec/workers/articles/enrich_image_attributes_worker_spec.rb +++ b/spec/workers/articles/enrich_image_attributes_worker_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Articles::EnrichImageAttributesWorker, type: :worker do - include_examples "#enqueues_on_correct_queue", "medium_priority", 1 + include_examples "#enqueues_on_correct_queue", "high_priority", 1 describe "#perform" do let(:worker) { subject }