-
Notifications
You must be signed in to change notification settings - Fork 0
FEATURE: automatically downsize large images #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: image-processing-optimization
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -139,25 +139,24 @@ def self.downsize_instructions_animated(from, to, dimensions, opts={}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def self.resize(from, to, width, height, opts={}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optimize("resize", from, to, width, height, opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optimize("resize", from, to, "#{width}x#{height}", opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def self.downsize(from, to, max_width, max_height, opts={}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optimize("downsize", from, to, max_width, max_height, opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optimize("downsize", from, to, "#{max_width}x#{max_height}", opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def self.optimize(operation, from, to, width, height, opts={}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dim = dimensions(width, height) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def self.downsize(from, to, dimensions, opts={}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
145
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The Severity Level: Major
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def self.downsize(from, to, max_width, max_height, opts={}) | |
| optimize("downsize", from, to, max_width, max_height, opts) | |
| optimize("downsize", from, to, "#{max_width}x#{max_height}", opts) | |
| end | |
| def self.optimize(operation, from, to, width, height, opts={}) | |
| dim = dimensions(width, height) | |
| def self.downsize(from, to, dimensions, opts={}) | |
| def self.downsize(from, to, *args) | |
| dimensions = nil | |
| opts = {} | |
| # Support: downsize(from, to, "80%", opts) | |
| if args.length == 2 && args[0].is_a?(String) && args[1].is_a?(Hash) | |
| dimensions = args[0] | |
| opts = args[1] | |
| # Support: downsize(from, to, max_width, max_height, opts) | |
| elsif args.length == 3 | |
| max_width, max_height, opts = args | |
| dimensions = "#{max_width}x#{max_height}" | |
| opts ||= {} | |
| # Support: downsize(from, to, max_width, max_height) | |
| elsif args.length == 2 | |
| max_width, max_height = args | |
| dimensions = "#{max_width}x#{max_height}" | |
| else | |
| raise ArgumentError, "wrong number of arguments (#{args.length + 2} for 4..5)" | |
| end | |
Steps of Reproduction ✅
1. Note that `OptimizedImage.downsize` is defined twice in
`app/models/optimized_image.rb:145-151`. In Ruby, the second definition (lines 149-151,
signature `(from, to, dimensions, opts={})`) overwrites the first definition `(from, to,
max_width, max_height, opts={})`.
2. Observe an existing caller in `app/jobs/regular/resize_emoji.rb:5-15`, where
`Jobs::ResizeEmoji#execute` calls `OptimizedImage.downsize(path, path, 100, 100, opts)`
(line 14), i.e., with 5 arguments: `from`, `to`, `max_width`, `max_height`, and `opts`.
3. With the PR's final file state, when the `ResizeEmoji` job runs (enqueued in
`app/models/emoji.rb:73` via `Jobs.enqueue(:resize_emoji, path: path)` after emoji
changes), Ruby dispatches to the *second* `downsize` definition, whose method signature is
`(from, to, dimensions, opts={})` and therefore expects at most 4 arguments.
4. At runtime, calling `OptimizedImage.downsize(path, path, 100, 100, opts)` now passes 5
arguments to a 4-parameter method, causing `ArgumentError: wrong number of arguments
(given 5, expected 3..4)` and the `Jobs::ResizeEmoji` background job fails whenever it
executes.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** app/models/optimized_image.rb
**Line:** 145:149
**Comment:**
*Logic Error: The `OptimizedImage.downsize` class method is defined twice with different parameter lists, and the second definition overwrites the first, so existing callers like `OptimizedImage.downsize(path, path, 100, 100, opts)` now pass too many arguments to the final method and will raise an `ArgumentError` at runtime. You should collapse these into a single `downsize` implementation that can handle both the old `(from, to, width, height, opts)` style and the new `(from, to, dimensions, opts)` style using a flexible argument list.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The client-side upload validation now uses a hardcoded 10MB limit for all uploads, ignoring per-type site settings like
max_attachment_size_kb, so attachments larger than the configured limit will pass the browser check and only fail later on the server, leading to inconsistent behavior and confusing errors. You should keep the 10MB allowance only for images (which are downsized server-side) and continue to honor the site setting for attachments. [logic error]Severity Level: Major⚠️
Steps of Reproduction ✅
Prompt for AI Agent 🤖