Skip to content

Check that the card is NSG before serving xlarge images #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/models/printing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def latest_printing_id
nil
end

def xlarge_image?
# The excluded sets were designed by FFG despite being released by NSG. We do not want to distribute high quality
# versions of them.
released_by == 'null_signal_games' &&
!%w[
system_core_2019
magnum_opus_reprint
salvaged_memories
system_update_2021
].include?(card_set_id)
end

def restrictions
{
banned: restrictions_banned,
Expand Down
14 changes: 9 additions & 5 deletions app/resources/card_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength

unless @object.num_extra_faces.zero?
@object.face_indices.each do |index|
f = { index:, images: images(@object.latest_printing_id, face_index: index) }
f = { index:,
images: images(@object.latest_printing_id,
@object.printings.order(:date_release).reverse_order.first.xlarge_image?,
face_index: index) }
f[:base_link] = @object.faces_base_link[index] if @object.faces_base_link[index]
f[:display_subtypes] = @object.faces_display_subtypes[index] if @object.faces_display_subtypes[index]
f[:card_subtype_ids] = @object.faces_card_subtype_ids[index].compact if @object.faces_card_subtype_ids[index]
Expand All @@ -93,7 +96,8 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength
attribute :restrictions, :hash
attribute :latest_printing_id, :string
attribute :latest_printing_images, :hash do
images(@object.latest_printing_id, has_narrative_image: @object.narrative_text.present?)
images(@object.latest_printing_id, @object.printings.order(:date_release).reverse_order.first.xlarge_image?,
has_narrative_image: @object.narrative_text.present?)
end

filter :card_cycle_id, :string do
Expand Down Expand Up @@ -163,16 +167,16 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength

private

def images(id, has_narrative_image: false, face_index: nil)
def images(id, has_xlarge_image, has_narrative_image: false, face_index: nil)
url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix
face_suffix = "-#{face_index}" unless face_index.nil?
image_sizes = {
'tiny' => "#{url_prefix}/tiny/#{id}#{face_suffix}.jpg",
'small' => "#{url_prefix}/small/#{id}#{face_suffix}.jpg",
'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg",
'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg",
'xlarge' => "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp"
'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg"
}
image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if has_xlarge_image

image_sizes['narrative'] = "#{url_prefix}/xlarge/#{id}#{face_suffix}-narrative.webp" if has_narrative_image

Expand Down
10 changes: 5 additions & 5 deletions app/resources/printing_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng
attribute :pronunciation_ipa, :string

attribute :images, :hash do
images(@object.id, has_narrative_image: @object.narrative_text.present?)
images(@object.id, @object.xlarge_image?, has_narrative_image: @object.narrative_text.present?)
end
attribute :card_abilities, :hash
attribute :latest_printing_id, :string
Expand All @@ -99,7 +99,7 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng

unless @object.num_extra_faces.zero?
@object.face_indices.each do |index|
f = { index:, images: images(@object.id, face_index: index) }
f = { index:, images: images(@object.id, @object.xlarge_image?, face_index: index) }
f[:base_link] = @object.faces_base_link[index] if @object.faces_base_link[index]
f[:copy_quantity] = @object.faces_copy_quantity[index] if @object.faces_copy_quantity[index]
f[:flavor] = @object.faces_flavor[index] if @object.faces_flavor[index]
Expand Down Expand Up @@ -179,16 +179,16 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng

private

def images(id, has_narrative_image: false, face_index: nil)
def images(id, has_xlarge_image, has_narrative_image: false, face_index: nil)
url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix
face_suffix = "-#{face_index}" unless face_index.nil?
image_sizes = {
'tiny' => "#{url_prefix}/tiny/#{id}#{face_suffix}.jpg",
'small' => "#{url_prefix}/small/#{id}#{face_suffix}.jpg",
'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg",
'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg",
'xlarge' => "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp"
'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg"
}
image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if has_xlarge_image

image_sizes['narrative'] = "#{url_prefix}/xlarge/#{id}#{face_suffix}-narrative.webp" if has_narrative_image

Expand Down
25 changes: 25 additions & 0 deletions spec/resources/card_resource_reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@
end
end

describe 'has xlarge image' do
let!(:card) { Card.find('hoshiko_shiro_untold_protagonist') }

it 'has xlarge image' do
params[:filter] = { id: { eq: card.id } }
render

data = jsonapi_data[0]
expect(data.latest_printing_images[:nrdb_classic][:xlarge]).to eq("https://card-images.netrunnerdb.com/v2/xlarge/#{card.latest_printing_id}.webp")
expect(data.faces[0][:images][:nrdb_classic][:xlarge]).to eq("https://card-images.netrunnerdb.com/v2/xlarge/#{card.latest_printing_id}-0.webp")
end
end

describe 'no xlarge image' do
let!(:card) { Card.find('adonis_campaign') }

it 'no xlarge image' do
params[:filter] = { id: { eq: card.id } }
render

data = jsonapi_data[0]
expect(data.latest_printing_images[:nrdb_classic][:xlarge]).to be_falsy
end
end

describe 'filtering' do
let!(:card) { Card.find('pennyshaver') }

Expand Down
25 changes: 25 additions & 0 deletions spec/resources/printing_resource_reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@
end
end

describe 'has xlarge image' do
let!(:printing) { Printing.find('01072') } # Hoshiko

it 'has xlarge image' do
params[:filter] = { id: { eq: printing.id } }
render

data = jsonapi_data[0]
expect(data.images[:nrdb_classic][:xlarge]).to eq("https://card-images.netrunnerdb.com/v2/xlarge/#{printing.id}.webp")
expect(data.faces[0][:images][:nrdb_classic][:xlarge]).to eq("https://card-images.netrunnerdb.com/v2/xlarge/#{printing.id}-0.webp")
end
end

describe 'no xlarge image' do
let!(:printing) { Printing.find('01056') } # Adonis Campaign

it 'no xlarge image' do
params[:filter] = { id: { eq: printing.id } }
render

data = jsonapi_data[0]
expect(data.images[:nrdb_classic][:xlarge]).to be_falsy
end
end

describe 'filtering' do
let!(:printing) { Printing.find('21180') }

Expand Down