Fixed bugs, added specs, extracted the upload downsizing code to a class, added support for non-S3 setups, changed it so that images aren’t downloaded twice.
Btw. this code has been tested on production and successfully resized ~180k uploads.
50% less repetition (ie. 1 less
path = if upload.local? Discourse.store.path_for(upload) else (Discourse.store.download(upload, max_file_size_kb: 100.megabytes) rescue nil)&.path end