return approved screenshots only in public json. fixes #96
This commit is contained in:
parent
e2473ff511
commit
9d0009b129
3 changed files with 16 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue