From 2b70a95434367b60c49581bd31b66f10bdd07f10 Mon Sep 17 00:00:00 2001 From: Lia Huynh Date: Sun, 17 Aug 2025 23:30:35 -0700 Subject: [PATCH 1/4] Check that the card is NSG before serving xlarge images --- app/resources/card_resource.rb | 10 +++++----- app/resources/printing_resource.rb | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/resources/card_resource.rb b/app/resources/card_resource.rb index 7fd713f..f428532 100644 --- a/app/resources/card_resource.rb +++ b/app/resources/card_resource.rb @@ -74,7 +74,7 @@ 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.designed_by, 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] @@ -93,7 +93,7 @@ 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.designed_by, has_narrative_image: @object.narrative_text.present?) end filter :card_cycle_id, :string do @@ -163,16 +163,16 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength private - def images(id, has_narrative_image: false, face_index: nil) + def images(id, designed_by, 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 designed_by == 'null_signal_games' image_sizes['narrative'] = "#{url_prefix}/xlarge/#{id}#{face_suffix}-narrative.webp" if has_narrative_image diff --git a/app/resources/printing_resource.rb b/app/resources/printing_resource.rb index b2d4dfe..27886ed 100644 --- a/app/resources/printing_resource.rb +++ b/app/resources/printing_resource.rb @@ -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.designed_by, has_narrative_image: @object.narrative_text.present?) end attribute :card_abilities, :hash attribute :latest_printing_id, :string @@ -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.designed_by, 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] @@ -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, designed_by, 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 designed_by == 'null_signal_games' image_sizes['narrative'] = "#{url_prefix}/xlarge/#{id}#{face_suffix}-narrative.webp" if has_narrative_image From 7ba8eaef705608f76bdb1e998c744fe34761856b Mon Sep 17 00:00:00 2001 From: Lia Huynh Date: Wed, 20 Aug 2025 02:09:07 -0700 Subject: [PATCH 2/4] Use released_by instead of designed_by, excluding some sets. Add tests --- app/models/printing.rb | 10 ++++++++ app/resources/card_resource.rb | 9 ++++--- app/resources/printing_resource.rb | 8 +++--- spec/resources/card_resource_reads_spec.rb | 25 +++++++++++++++++++ .../resources/printing_resource_reads_spec.rb | 25 +++++++++++++++++++ 5 files changed, 69 insertions(+), 8 deletions(-) diff --git a/app/models/printing.rb b/app/models/printing.rb index e87a5f6..72d5ad7 100644 --- a/app/models/printing.rb +++ b/app/models/printing.rb @@ -43,6 +43,16 @@ def latest_printing_id nil end + def xlarge_image? + 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, diff --git a/app/resources/card_resource.rb b/app/resources/card_resource.rb index f428532..9b72f6b 100644 --- a/app/resources/card_resource.rb +++ b/app/resources/card_resource.rb @@ -74,7 +74,7 @@ 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, @object.designed_by, face_index: index) } + f = { index:, images: images(@object.latest_printing_id, 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] @@ -93,7 +93,7 @@ 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, @object.designed_by, has_narrative_image: @object.narrative_text.present?) + images(@object.latest_printing_id, has_narrative_image: @object.narrative_text.present?) end filter :card_cycle_id, :string do @@ -163,7 +163,8 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength private - def images(id, designed_by, has_narrative_image: false, face_index: nil) + def images(id, has_narrative_image: false, face_index: nil) + printing = Printing.find(id) url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix face_suffix = "-#{face_index}" unless face_index.nil? image_sizes = { @@ -172,7 +173,7 @@ def images(id, designed_by, has_narrative_image: false, face_index: nil) 'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg", 'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg" } - image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if designed_by == 'null_signal_games' + image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if printing.xlarge_image? image_sizes['narrative'] = "#{url_prefix}/xlarge/#{id}#{face_suffix}-narrative.webp" if has_narrative_image diff --git a/app/resources/printing_resource.rb b/app/resources/printing_resource.rb index 27886ed..2a01bf1 100644 --- a/app/resources/printing_resource.rb +++ b/app/resources/printing_resource.rb @@ -85,7 +85,7 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng attribute :pronunciation_ipa, :string attribute :images, :hash do - images(@object.id, @object.designed_by, 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 @@ -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, @object.designed_by, 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] @@ -179,7 +179,7 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng private - def images(id, designed_by, 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 = { @@ -188,7 +188,7 @@ def images(id, designed_by, has_narrative_image: false, face_index: nil) 'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg", 'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg" } - image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if designed_by == 'null_signal_games' + 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 diff --git a/spec/resources/card_resource_reads_spec.rb b/spec/resources/card_resource_reads_spec.rb index e2e5983..77712c1 100644 --- a/spec/resources/card_resource_reads_spec.rb +++ b/spec/resources/card_resource_reads_spec.rb @@ -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') } diff --git a/spec/resources/printing_resource_reads_spec.rb b/spec/resources/printing_resource_reads_spec.rb index ddd0ace..dd98684 100644 --- a/spec/resources/printing_resource_reads_spec.rb +++ b/spec/resources/printing_resource_reads_spec.rb @@ -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') } From 62995fb9361b041b2a0fc65cba998efcf11f7ac3 Mon Sep 17 00:00:00 2001 From: Lia Huynh Date: Thu, 21 Aug 2025 00:44:42 -0700 Subject: [PATCH 3/4] Removed extra Printing access, add a comment --- app/models/printing.rb | 2 ++ app/resources/card_resource.rb | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/printing.rb b/app/models/printing.rb index 72d5ad7..97cc97e 100644 --- a/app/models/printing.rb +++ b/app/models/printing.rb @@ -44,6 +44,8 @@ def latest_printing_id 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 diff --git a/app/resources/card_resource.rb b/app/resources/card_resource.rb index 9b72f6b..3bedfc0 100644 --- a/app/resources/card_resource.rb +++ b/app/resources/card_resource.rb @@ -74,7 +74,8 @@ 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.last.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] @@ -93,7 +94,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.last.xlarge_image?, + has_narrative_image: @object.narrative_text.present?) end filter :card_cycle_id, :string do @@ -163,8 +165,7 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength private - def images(id, has_narrative_image: false, face_index: nil) - printing = Printing.find(id) + 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 = { @@ -173,7 +174,7 @@ def images(id, has_narrative_image: false, face_index: nil) 'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg", 'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg" } - image_sizes[:xlarge] = "#{url_prefix}/xlarge/#{id}#{face_suffix}.webp" if printing.xlarge_image? + 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 From f29bd90759047cc31c117fa7fd3b4ed939db8f8f Mon Sep 17 00:00:00 2001 From: Lia Huynh Date: Fri, 22 Aug 2025 16:23:09 -0700 Subject: [PATCH 4/4] sort printings in release order --- app/resources/card_resource.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/resources/card_resource.rb b/app/resources/card_resource.rb index 3bedfc0..65cc466 100644 --- a/app/resources/card_resource.rb +++ b/app/resources/card_resource.rb @@ -75,7 +75,9 @@ 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, @object.printings.last.xlarge_image?, face_index: 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] @@ -94,7 +96,7 @@ 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, @object.printings.last.xlarge_image?, + images(@object.latest_printing_id, @object.printings.order(:date_release).reverse_order.first.xlarge_image?, has_narrative_image: @object.narrative_text.present?) end