/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
# dummy image along with status 404.
def thumbnail
# TODO: redirect to static thumbnail image URL
@package = Package.find_by(name: params[:name])
unless @package
#logger.debug "Thumbnail for package '#{params[:name]}' requested. No such package found."
thumbnail404
return
end
@ -185,13 +187,15 @@ class PackagesController < ApplicationController
end
# 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
# 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
return
end
# Send the thumbnail (uses X-Sendfile or similar if possible)
send_file @screenshot.image.path(:thumb), type: "image/png", disposition: 'inline'
redirect_to @screenshot.simage_url(:thumb)
end
# Returns a large screenshot image if posssible.
@ -219,8 +223,7 @@ class PackagesController < ApplicationController
return
end
# Send the thumbnail (uses X-Sendfile or similar if possible)
send_file @screenshot.image.path(:large), type: "image/png", disposition: 'inline'
redirect_to @screenshot.simage_url(:large)
end
# 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."
def thumbnail404
send_file Rails.root.join('public/images/dummy/thumbnail404.png'),
type: "image/png",
disposition: 'inline',
status: 404
redirect_to '/images/dummy/thumbnail404.png', status: 404
end
def screenshot404
send_file Rails.root.join('public/images/dummy/screenshot404.png'),
type: "image/png",
disposition: 'inline',
status: 404
redirect_to '/images/dummy/screenshot404.png', status: 404
end
# Return packages matching the criteria given by parameters