Compare commits

..

No commits in common. "0244653cb0d327e76f844f09100e4f936bfb7d41" and "be0faaa36ea0f4b4c8c913fd6f864d24fea2dbe3" have entirely different histories.

9 changed files with 48 additions and 56 deletions

View file

@ -1,41 +1,27 @@
class PetTypesController < ApplicationController class PetTypesController < ApplicationController
def index def index
respond_to do |format| @species_names = Species.order(:name).map(&:human_name)
format.html { @color_names = Color.order(:name).map(&:human_name)
@species_names = Species.order(:name).map(&:human_name)
@color_names = Color.order(:name).map(&:human_name)
if params[:species].present? if params[:species].present?
@selected_species = Species.find_by!(name: params[:species]) @selected_species = Species.find_by!(name: params[:species])
@selected_species_name = @selected_species.human_name @selected_species_name = @selected_species.human_name
end end
if params[:color].present? if params[:color].present?
@selected_color = Color.find_by!(name: params[:color]) @selected_color = Color.find_by!(name: params[:color])
@selected_color_name = @selected_color.human_name @selected_color_name = @selected_color.human_name
end end
@pet_types = PetType. @pet_types = PetType.
includes(:color, :species, :pet_states). includes(:color, :species, :pet_states).
order(created_at: :desc). order(created_at: :desc).
paginate(page: params[:page], per_page: 30) paginate(page: params[:page], per_page: 30)
if @selected_species if @selected_species
@pet_types = @pet_types.where(species_id: @selected_species) @pet_types = @pet_types.where(species_id: @selected_species)
end end
if @selected_color if @selected_color
@pet_types = @pet_types.where(color_id: @selected_color) @pet_types = @pet_types.where(color_id: @selected_color)
end
}
format.json {
if stale?(etag: PetState.last_updated_key)
render json: {
species: Species.order(:name).all,
colors: Color.order(:name).all,
supported_poses: PetState.all_supported_poses,
}
end
}
end end
end end

View file

@ -1,5 +1,6 @@
class PetsController < ApplicationController class PetsController < ApplicationController
rescue_from Pet::PetNotFound, with: :pet_not_found rescue_from Pet::PetNotFound, with: :pet_not_found
rescue_from PetType::DownloadError, SwfAsset::DownloadError, with: :asset_download_error
rescue_from Pet::DownloadError, with: :pet_download_error rescue_from Pet::DownloadError, with: :pet_download_error
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
@ -47,6 +48,12 @@ class PetsController < ApplicationController
:status => :not_found :status => :not_found
end end
def asset_download_error(e)
Rails.logger.warn e.message
pet_load_error :long_message => t('pets.load.asset_download_error'),
:status => :gateway_timeout
end
def pet_download_error(e) def pet_download_error(e)
Rails.logger.warn e.message Rails.logger.warn e.message
Rails.logger.warn e.backtrace.join("\n") Rails.logger.warn e.backtrace.join("\n")

View file

@ -12,7 +12,7 @@ class PetState < ApplicationRecord
belongs_to :pet_type belongs_to :pet_type
delegate :species_id, :species, :color_id, :color, to: :pet_type delegate :color, to: :pet_type
alias_method :swf_asset_ids_from_association, :swf_asset_ids alias_method :swf_asset_ids_from_association, :swf_asset_ids
@ -209,23 +209,5 @@ class PetState < ApplicationRecord
self.female = female self.female = female
self.unconverted = unconverted self.unconverted = unconverted
end end
def self.last_updated_key
PetState.maximum(:id)
end
def self.all_supported_poses
Rails.cache.fetch("PetState.all_supported_poses #{last_updated_key}") do
{}.tap do |h|
includes(:pet_type).find_each do |pet_state|
h[pet_state.species_id] ||= {}
h[pet_state.species_id][pet_state.color_id] ||= []
h[pet_state.species_id][pet_state.color_id] << pet_state.pose
end
h.values.map(&:values).flatten(1).each(&:uniq!).each(&:sort!)
end
end
end
end end

View file

@ -156,5 +156,7 @@ class PetType < ApplicationRecord
end end
end end
end end
class DownloadError < Exception;end
end end

View file

@ -2,6 +2,8 @@ require 'addressable/template'
require 'async' require 'async'
require 'async/barrier' require 'async/barrier'
require 'async/semaphore' require 'async/semaphore'
require 'fileutils'
require 'uri'
class SwfAsset < ApplicationRecord class SwfAsset < ApplicationRecord
# We use the `type` column to mean something other than what Rails means! # We use the `type` column to mean something other than what Rails means!
@ -371,4 +373,6 @@ class SwfAsset < ApplicationRecord
# linked to it, meaning that it's probably wearable by all bodies. # linked to it, meaning that it's probably wearable by all bodies.
self.body_id = 0 if !@body_id_overridden && (!self.body_specific? || (!self.new_record? && self.body_id_changed?)) self.body_id = 0 if !@body_id_overridden && (!self.body_specific? || (!self.new_record? && self.body_id_changed?))
end end
class DownloadError < Exception;end
end end

View file

@ -35,8 +35,7 @@ en-MEEP:
terms: Terms of Use (meeped Sep 2022) terms: Terms of Use (meeped Sep 2022)
contact: Meeptact contact: Meeptact
email: Questions, comments, meepits email: Questions, comments, meepits
copyright: copyright: Images © 1999%{year} World of Neopets, Inc. All Rights Reserved.
Images © 1999%{year} World of Neopets, Inc. All Rights Reserved.
Used With Permission. Meep. Used With Permission. Meep.
items: items:
@ -635,6 +634,10 @@ en-MEEP:
load: load:
not_found: We couldn't meep a pet by that name. Is it meeped correctly? not_found: We couldn't meep a pet by that name. Is it meeped correctly?
asset_download_error:
We meeped the pet and what it's wearing, but couldn't meep the
associated meepia files. Maybe Neopets is down, or changed their
firewall rules? Please meep again later!
pet_download_error: pet_download_error:
We couldn't meep to Neopets to meep up the pet. Maybe they're down. We couldn't meep to Neopets to meep up the pet. Maybe they're down.
Please try meep later! Please try meep later!

View file

@ -755,6 +755,10 @@ en:
load: load:
not_found: We couldn't find a pet by that name. Is it spelled correctly? not_found: We couldn't find a pet by that name. Is it spelled correctly?
asset_download_error:
We found the pet and what it's wearing, but couldn't download the
associated media files. Maybe Neopets is down, or changed their
firewall rules? Please try again later!
pet_download_error: pet_download_error:
We couldn't connect to Neopets to look up the pet. Maybe they're down. We couldn't connect to Neopets to look up the pet. Maybe they're down.
Please try again later! Please try again later!

View file

@ -116,7 +116,8 @@ es:
submit: Guardar submit: Guardar
edit: Editar edit: Editar
delete: Eliminar delete: Eliminar
delete_confirmation: ¿Estás seguro/a que quieres eliminar la lista "%{list_name}"? delete_confirmation:
¿Estás seguro/a que quieres eliminar la lista "%{list_name}"?
empty: Esta lista está vacía. empty: Esta lista está vacía.
edit: edit:
title: Editando la lista "%{list_name}" title: Editando la lista "%{list_name}"
@ -502,6 +503,7 @@ es:
submission_success: "%{points} puntos" submission_success: "%{points} puntos"
load: load:
not_found: No hemos podido encontrar a un pet con ese nombre. ¿Lo has escrito correctamente? not_found: No hemos podido encontrar a un pet con ese nombre. ¿Lo has escrito correctamente?
asset_download_error: Hemos encontrado el pet que intentas vestir, pero no hemos podido descargar las imágenes que lo asocian. Posiblemente Neopets está caído. ¡Por favor inténtalo de nuevo más tarde!
pet_download_error: No hemos podido conectar con Neopets para ver tu pet. Posiblemente el servidor de Neopets se ha caído. ¡Por favor inténtalo de nuevo más tarde! pet_download_error: No hemos podido conectar con Neopets para ver tu pet. Posiblemente el servidor de Neopets se ha caído. ¡Por favor inténtalo de nuevo más tarde!
users: users:
index: index:

View file

@ -114,7 +114,8 @@ pt:
submit: Salvar submit: Salvar
edit: Editar edit: Editar
delete: Excluir delete: Excluir
delete_confirmation: Você tem certeza que deseja excluir "%{list_name}"? delete_confirmation:
Você tem certeza que deseja excluir "%{list_name}"?
empty: Esta lista está vazia. empty: Esta lista está vazia.
edit: edit:
title: Editando lista "%{list_name}" title: Editando lista "%{list_name}"
@ -496,6 +497,7 @@ pt:
submission_success: "%{points} pontos" submission_success: "%{points} pontos"
load: load:
not_found: Não foi possível achar um pet com esse nome. Está escrito corretamente? not_found: Não foi possível achar um pet com esse nome. Está escrito corretamente?
asset_download_error: Nós achamos o pet e o que ele está vestindo, mas não foi possível baixar os dados. Talvez Neopets esteja fora do ar. Por favor tente mais tarde!
pet_download_error: Nós não conseguimos conectar ao Neopets para achar o pet. Talvez eles estejam fora do ar. Por favor tente mais tarde! pet_download_error: Nós não conseguimos conectar ao Neopets para achar o pet. Talvez eles estejam fora do ar. Por favor tente mais tarde!
users: users:
index: index: