A platform for community discussion. Free, open, simple.
FIX: Handle failed download when calculating image dominant color (#18342)
David Taylor42947ec6f122
diff --git a/app/models/upload.rb b/app/models/upload.rbindex be5deaaa6bb..f218a9c741f 100644--- a/app/models/upload.rb+++ b/app/models/upload.rb@@ -340,10 +340,15 @@ class Upload < ActiveRecord::Baseif local?Discourse.store.path_for(self)else- Discourse.store.download(self).path+ Discourse.store.download(self)&.pathend- color = begin+ if local_path.nil?+ # Download failed. Could be too large to download, or file could be missing in s3+ color = ""+ end++ color ||= begindata = Discourse::Utils.execute_command("nice","-n",diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rbindex 2ce566ed264..34862ff23ce 100644--- a/spec/models/upload_spec.rb+++ b/spec/models/upload_spec.rb@@ -690,6 +690,15 @@ RSpec.describe Upload doexpect(invalid_image.dominant_color).to eq(nil)end+ it "correctly handles download failures" do+ white_image.stubs(:local?).returns(true)+ Discourse.store.stubs(:download).returns(nil)++ expect(invalid_image.dominant_color).to eq(nil)+ expect(invalid_image.dominant_color(calculate_if_missing: true)).to eq("")+ expect(invalid_image.dominant_color).to eq("")+ end+it "is validated for length" dou = Fabricate(:upload)