From baaa419f0095b0e03e6a37ef092c9254722bdcf4 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sat, 13 Feb 2021 22:15:57 +0100 Subject: [PATCH] /thumbnail and /screenshot redirect properly to Shrine file --- app/controllers/packages_controller.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index d0115f5..f70d0fc 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -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