imgproxy.rb icon indicating copy to clipboard operation
imgproxy.rb copied to clipboard

shrine compatibility?

Open bluengreen opened this issue 2 years ago • 5 comments

The docs say this gem is compatible with shrine but I get this error in a rails 6.1.5 app, using ruby 2.7.2 and shrine 3. If I remove imgproxy.rb works as normal. If I downgrade imgproxy works fine. But if I have the latest of imgproxy.rb rails s crashes with the error below.

/Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/anyway/type_casting.rb:111: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
/Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/anyway/rbs.rb:40: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
Traceback (most recent call last):
	32: from bin/rails:4:in `<main>'
	31: from bin/rails:4:in `require'
	30: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/commands.rb:18:in `<top (required)>'
	29: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/command.rb:48:in `invoke'
	28: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/command/base.rb:69:in `perform'
	27: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
	26: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	25: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	24: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/commands/server/server_command.rb:135:in `perform'
	23: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/commands/server/server_command.rb:135:in `tap'
	22: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/railties-6.1.5/lib/rails/commands/server/server_command.rb:138:in `block in perform'
	21: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/activesupport-6.1.5/lib/active_support/dependencies.rb:332:in `require'
	20: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/activesupport-6.1.5/lib/active_support/dependencies.rb:299:in `load_dependency'
	19: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/activesupport-6.1.5/lib/active_support/dependencies.rb:332:in `block in require'
	18: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/activesupport-6.1.5/lib/active_support/dependencies.rb:332:in `require'
	17: from /Users/pnovess/Projects/designious-api/config/application.rb:20:in `<top (required)>'
	16: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler.rb:174:in `require'
	15: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:50:in `require'
	14: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:50:in `each'
	13: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:61:in `block in require'
	12: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:61:in `each'
	11: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:66:in `block (2 levels) in require'
	10: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/bundler-2.2.19/lib/bundler/runtime.rb:66:in `require'
	 9: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/imgproxy-2.0.1/lib/imgproxy.rb:149:in `<top (required)>'
	 8: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/imgproxy-2.0.1/lib/imgproxy.rb:143:in `extend_shrine!'
	 7: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/imgproxy-2.0.1/lib/imgproxy.rb:15:in `config'
	 6: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/imgproxy-2.0.1/lib/imgproxy.rb:15:in `new'
	 5: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/.rbnext/3.0/anyway/config.rb:337:in `initialize'
	 4: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/.rbnext/3.0/anyway/config.rb:355:in `load'
	 3: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/.rbnext/3.0/anyway/tracing.rb:133:in `capture'
	 2: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/.rbnext/3.0/anyway/config.rb:358:in `block in load'
	 1: from /Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/.rbnext/3.0/anyway/config.rb:407:in `resolve_config_path'
/Users/pnovess/.rvm/gems/ruby-2.7.2@designious_api/gems/anyway_config-2.3.0/lib/anyway/rails/settings.rb:67:in `block in <class:Settings>': undefined method `join' for nil:NilClass (NoMethodError)

bluengreen avatar Apr 20 '22 03:04 bluengreen

Hi @bluengreen! This looks like an anyway_config issue.

DarthSim avatar Jun 13 '22 14:06 DarthSim

@DarthSim yeah that’s what I thought as well but wasn’t really sure where to start. Kinda new to anyway_config. I reverted to the older version. But I was actually thinking it may be more useful to have the functionality this gem provides in my front end app rather than in my rails api. Is there a js version package you would recommend? Is that something that you’re thinking of adding?

Thanks!

bluengreen avatar Jun 13 '22 16:06 bluengreen

@bluengreen According to your stack trace, your Rails.root is nil somehow which is quite unusual if I remember Rails stuff right. anyway_config tries to use the join method of Rails.root, and since it's nil, you get the error here. If Rails.root should be nil in your case, I'd recommend you create an issue in the anyway_config repo.

If you're going to sign your imgproxy URLs (that I highly recommend) doing so on the front-end side is quite meaningless. If you have a key/salt pair on the front-end side, then an attacker can see it and use it to generate new URLs for your imgproxy instance. I believe that there are some Node.js packages for imgproxy anyway.

DarthSim avatar Jun 14 '22 08:06 DarthSim

@DarthSim ah I think at the time I tried it, my root route was not set. It was a new project. I’ll try upgrading it now that I have root set and see if that fixes it. As for the front end I see what you mean. However I’m using Nextjs so I could have those fucntions rendered server side with private secrets.

Thanks I’ll let you know if that resolved it.

bluengreen avatar Jun 14 '22 13:06 bluengreen

@DarthSim ok not really sure if all the functionality is working as it should yet but at least I can get it to load the app without crashing. This part in the instructions doesn't seem to be automagically doing its thing correctly. Which is why Rails.root is nil. Something is clobbering the name passed to the config. I didn't go too far down the rabbit holes.

You can also use imgproxy.rb's built-in Shrine support. It is enabled automagically if you load imgproxy gem after shrine (basically, just put gem "imgproxy" after gem "shrine" in your Gemfile). Otherwise, modify your initializer at config/initializers/imgproxy.rb:

I got the app at least loading again by not following that instruction and add imgproxy.rb before shrine in my gemfile, and using the Imgproxy.extend_shrine!

gem 'imgproxy', '~> 2.0'
gem 'shrine'

Not sure if everything else is working as it should yet.

bluengreen avatar Jul 07 '22 01:07 bluengreen