/thumbnail and /screenshot redirect properly to Shrine file

This commit is contained in:
Christoph Haas 2021-02-13 22:15:57 +01:00
parent 294b55f591
commit baaa419f00

View file

@ -170,8 +170,10 @@ class PackagesController < ApplicationController
# If the package is found but has no screenshots then it also returns a # If the package is found but has no screenshots then it also returns a
# dummy image along with status 404. # dummy image along with status 404.
def thumbnail def thumbnail
# TODO: redirect to static thumbnail image URL
@package = Package.find_by(name: params[:name]) @package = Package.find_by(name: params[:name])
unless @package unless @package
#logger.debug "Thumbnail for package '#{params[:name]}' requested. No such package found."
thumbnail404 thumbnail404
return return
end end
@ -185,13 +187,15 @@ class PackagesController < ApplicationController
end end
# Return a 404 if the package has no screenshots or the image was not found # Return a 404 if the package has no screenshots or the image was not found
thumbnail_path = @screenshot.image.path(:large)
unless @screenshot and @screenshot.image.path unless @screenshot and @screenshot.image.path
# Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
#logger.debug "Thumbnail for package '#{params[:name]}' requested. No screenshot or file not found."
thumbnail404 thumbnail404
return return
end end
# Send the thumbnail (uses X-Sendfile or similar if possible) redirect_to @screenshot.simage_url(:thumb)
send_file @screenshot.image.path(:thumb), type: "image/png", disposition: 'inline'
end end
# Returns a large screenshot image if posssible. # Returns a large screenshot image if posssible.
@ -219,8 +223,7 @@ class PackagesController < ApplicationController
return return
end end
# Send the thumbnail (uses X-Sendfile or similar if possible) redirect_to @screenshot.simage_url(:large)
send_file @screenshot.image.path(:large), type: "image/png", disposition: 'inline'
end end
# Receives a form with a simple text field 'description' so that users can update # Receives a form with a simple text field 'description' so that users can update
@ -264,17 +267,11 @@ class PackagesController < ApplicationController
# Send a dummy thumbnail reading "No screenshot available. Sorry." # Send a dummy thumbnail reading "No screenshot available. Sorry."
def thumbnail404 def thumbnail404
send_file Rails.root.join('public/images/dummy/thumbnail404.png'), redirect_to '/images/dummy/thumbnail404.png', status: 404
type: "image/png",
disposition: 'inline',
status: 404
end end
def screenshot404 def screenshot404
send_file Rails.root.join('public/images/dummy/screenshot404.png'), redirect_to '/images/dummy/screenshot404.png', status: 404
type: "image/png",
disposition: 'inline',
status: 404
end end
# Return packages matching the criteria given by parameters # Return packages matching the criteria given by parameters