diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index dcd1a2d..1275edd 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -77,34 +77,15 @@ class PackagesController < ApplicationController thumbnail404 return end - @screenshot = @package.screenshots.first - # Return a 404 if the package has no screenshots or the image was not found - unless @screenshot and @screenshot.image.path - thumbnail404 - return + # Called as /thumbnail-with-version/:name/:version + if params[:version] + @screenshot = @package.best_screenshot_for_version(params[:version]) + # Called as /thumbnail/:name + else + @screenshot = @package.screenshots.first end - # Send the thumbnail - # TODO: Make sure it uses X-Sendfile correctly in production - send_file @screenshot.image.path(:thumb), type: "image/png", disposition: 'inline' - end - - # Similar to 'def thumbnail'. But tries to find a screenshot that matches the given version best. - # This algorithm collects all image - # versions of a package and determines the (second) newest version. - # E.g. if there are version 1.0 and 2.0 and the user is looking for - # a screenshot of version 1.5 then the 1.0 version is returned. - # This way the user does not see a screenshot of version 2.0 because - # 2.0 might contain features that were not there in version 1.5. - def thumbnail_with_version - @package = Package.find_by(name: params[:name]) - unless @package - thumbnail404 - return - end - @screenshot = @package.best_screenshot_for_version(params[:version]) - # Return a 404 if the package has no screenshots or the image was not found unless @screenshot and @screenshot.image.path thumbnail404 diff --git a/config/routes.rb b/config/routes.rb index c2e9db3..f591dc0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,7 +27,7 @@ Debshots::Application.routes.draw do get 'approve_screenshot/:id' => 'packages#approve_screenshot', as: :approve_screenshot get 'about' => 'welcome#about' get 'thumbnail/:name' => 'packages#thumbnail', as: :thumbnail_image, name: /[^\/]+/ - get 'thumbnail-with-version/:name/:version' => 'packages#thumbnail_with_version', name: /[^\/]+/, version: /\S+/ + get 'thumbnail-with-version/:name/:version' => 'packages#thumbnail', name: /[^\/]+/, version: /\S+/ # Legacy URLs get 'with_screenshots', to: redirect('/packages?show=with')