From 9d0009b129270766393f7b1fbf64f29c514580f5 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Wed, 4 Feb 2026 00:09:43 +0100 Subject: [PATCH] return approved screenshots only in public json. fixes #96 --- app/controllers/json_controller.rb | 2 +- app/models/package.rb | 5 +++++ app/views/json/package.json.jbuilder | 14 ++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/json_controller.rb b/app/controllers/json_controller.rb index b9959ae..3e6aa1d 100644 --- a/app/controllers/json_controller.rb +++ b/app/controllers/json_controller.rb @@ -8,7 +8,7 @@ class JsonController < ApplicationController # JSON information on all packages def packages expires_in 1.days, public: true - @p = Package.all + @p = Package.with_public_screenshots end # JSON information on all screenshots diff --git a/app/models/package.rb b/app/models/package.rb index 8245aa9..441f5c4 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -71,6 +71,11 @@ class Package < ApplicationRecord screenshots.approved.to_a.sort { |x, y| version_compare(x.version, y.version) } end + # Return all approved screenshots for this package + def approved_screenshots + screenshots.approved + end + # Return the newest screenshot that is not newer than the given version. # This algorithm collects all image # versions of a package and determines the (second) newest version. diff --git a/app/views/json/package.json.jbuilder b/app/views/json/package.json.jbuilder index 130f0af..b109103 100644 --- a/app/views/json/package.json.jbuilder +++ b/app/views/json/package.json.jbuilder @@ -1,8 +1,14 @@ json.package @p.name -json.screenshots @p.screenshots do |s| - json.thumb_image_url "#{request.protocol}#{request.host_with_port}#{s.simage_url(:thumb)}" - json.small_image_url "#{request.protocol}#{request.host_with_port}#{s.simage_url(:small)}" - json.large_image_url "#{request.protocol}#{request.host_with_port}#{s.simage_url(:large)}" +json.screenshots @p.approved_screenshots do |s| + json.thumb_image_url "#{request.protocol}#{request.host_with_port}#{thumbnail_with_id_path( + @p, s.id + )}" + json.small_image_url "#{request.protocol}#{request.host_with_port}#{small_image_with_id_path( + @p, s.id + )}" + json.screenshot_image_url "#{request.protocol}#{request.host_with_port}#{screenshot_image_with_id_path( + @p, s.id + )}" json.version s.version end