Skip to content

FEATURE: automatically downsize large images#10

Open
ShashankFC wants to merge 1 commit into
image-processing-optimizationfrom
large-image-processing
Open

FEATURE: automatically downsize large images#10
ShashankFC wants to merge 1 commit into
image-processing-optimizationfrom
large-image-processing

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Jan 22, 2026

Copy link
Copy Markdown

Test 1

Summary by CodeRabbit

  • New Features

    • Images exceeding the upload size limit are now automatically downsized to fit within allowed limits.
  • Refactor

    • Optimized image upload handling with improved automatic resizing capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.


Replicated from ai-code-review-evaluation/discourse-coderabbit#1


Note

Medium Risk
Touches upload validation and image processing paths; downsizing loops and the new 10MB hardcoded limits could change upload behavior and resource usage in production.

Overview
Enables oversized image uploads to be accepted by automatically downsizing them server-side until they fit within SiteSetting.max_image_size_kb (up to 5 attempts), instead of failing immediately.

Standardizes upload size handling by hardcoding a 10MB limit in the client-side validation/error messaging and in API URL-download handling, and refactors OptimizedImage resize/downsize helpers to pass dimensions as a single string to optimize.

Written by Cursor Bugbot for commit ffbaf8c. Configure here.

@ShashankFC

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

dim = dimensions(width, height)
def self.downsize(from, to, dimensions, opts={})
optimize("downsize", from, to, dimensions, opts)
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate downsize method breaks existing emoji resize callers

High Severity

Two def self.downsize methods are defined on OptimizedImage. In Ruby, the second definition (3 args: from, to, dimensions, opts={}) silently replaces the first (4 args: from, to, max_width, max_height, opts={}). The existing caller in ResizeEmoji passes 5 arguments (path, path, 100, 100, opts), which will raise an ArgumentError at runtime since the surviving method only accepts 3–4 arguments.

Additional Locations (1)

Fix in Cursor Fix in Web

// check file size
var fileSizeKB = file.size / 1024;
var maxSizeKB = Discourse.SiteSettings['max_' + type + '_size_kb'];
var maxSizeKB = 10 * 1024; // 10MB

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded upload limit ignores per-type site settings

Medium Severity

The client-side file size validation replaces the dynamic Discourse.SiteSettings['max_' + type + '_size_kb'] lookup with a hardcoded 10 * 1024 (10 MB) for all upload types. This removes the distinction between image and attachment limits, and ignores admin-configured size settings. Non-image attachments that pass client validation at 10 MB will still be rejected server-side if the configured max_attachment_size_kb is smaller, leading to confusing error behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants