Compare commits
5 commits
80307f21f7
...
f0257ba2d3
Author | SHA1 | Date | |
---|---|---|---|
f0257ba2d3 | |||
d056a5e766 | |||
5214a14990 | |||
06a89689d8 | |||
a08fb89d59 |
6 changed files with 111 additions and 6 deletions
|
@ -21,9 +21,12 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
class AccessDenied < StandardError; end
|
class AccessDenied < StandardError; end
|
||||||
rescue_from AccessDenied, with: :on_access_denied
|
rescue_from AccessDenied, with: :on_access_denied
|
||||||
|
|
||||||
rescue_from Async::Stop, Async::Container::Terminate,
|
rescue_from Async::Stop, Async::Container::Terminate,
|
||||||
with: :on_request_stopped
|
with: :on_request_stopped
|
||||||
|
|
||||||
|
rescue_from ActiveRecord::ConnectionTimeoutError, with: :on_db_timeout
|
||||||
|
|
||||||
def authenticate_user!
|
def authenticate_user!
|
||||||
redirect_to(new_auth_user_session_path) unless user_signed_in?
|
redirect_to(new_auth_user_session_path) unless user_signed_in?
|
||||||
end
|
end
|
||||||
|
@ -65,6 +68,11 @@ class ApplicationController < ActionController::Base
|
||||||
status: :internal_server_error
|
status: :internal_server_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_db_timeout
|
||||||
|
render file: 'public/503.html', layout: false,
|
||||||
|
status: :service_unavailable
|
||||||
|
end
|
||||||
|
|
||||||
def redirect_back!(default=:back)
|
def redirect_back!(default=:back)
|
||||||
redirect_to(params[:return_to] || default)
|
redirect_to(params[:return_to] || default)
|
||||||
end
|
end
|
||||||
|
|
|
@ -215,7 +215,8 @@ class ItemsController < ApplicationController
|
||||||
@item.compatible_pet_types.
|
@item.compatible_pet_types.
|
||||||
preferring_species(cookies["preferred-preview-species-id"] || "<ignore>").
|
preferring_species(cookies["preferred-preview-species-id"] || "<ignore>").
|
||||||
preferring_color(cookies["preferred-preview-color-id"] || "<ignore>").
|
preferring_color(cookies["preferred-preview-color-id"] || "<ignore>").
|
||||||
preferring_simple.first
|
preferring_simple.first ||
|
||||||
|
PetType.matching_name("Blue", "Acara").first!
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_preview
|
def validate_preview
|
||||||
|
|
|
@ -168,7 +168,7 @@ class Pet < ApplicationRecord
|
||||||
# Return the response body as a `HashWithIndifferentAccess`.
|
# Return the response body as a `HashWithIndifferentAccess`.
|
||||||
def self.send_amfphp_request(request, timeout: 10)
|
def self.send_amfphp_request(request, timeout: 10)
|
||||||
begin
|
begin
|
||||||
response = request.post(timeout: timeout, headers: {
|
response_data = request.post(timeout: timeout, headers: {
|
||||||
"User-Agent" => Rails.configuration.user_agent_for_neopets,
|
"User-Agent" => Rails.configuration.user_agent_for_neopets,
|
||||||
})
|
})
|
||||||
rescue RocketAMFExtensions::RemoteGateway::AMFError => e
|
rescue RocketAMFExtensions::RemoteGateway::AMFError => e
|
||||||
|
@ -177,7 +177,7 @@ class Pet < ApplicationRecord
|
||||||
raise DownloadError, e.message, e.backtrace
|
raise DownloadError, e.message, e.backtrace
|
||||||
end
|
end
|
||||||
|
|
||||||
HashWithIndifferentAccess.new(response.messages[0].data.body)
|
HashWithIndifferentAccess.new(response_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,20 @@ module NCMall
|
||||||
raise UnexpectedResponseFormat, "missing field object_data in NC page"
|
raise UnexpectedResponseFormat, "missing field object_data in NC page"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
object_data = nc_page["object_data"]
|
||||||
|
|
||||||
# NOTE: When there's no object data, it will be an empty array instead of
|
# NOTE: When there's no object data, it will be an empty array instead of
|
||||||
# an empty hash. Weird API thing to work around!
|
# an empty hash. Weird API thing to work around!
|
||||||
nc_page["object_data"] = {} if nc_page["object_data"] == []
|
object_data = {} if object_data == []
|
||||||
|
|
||||||
items = nc_page["object_data"].values.map do |item_info|
|
# Only the items in the `render` list are actually listed as directly for
|
||||||
|
# sale in the shop. `object_data` might contain other items that provide
|
||||||
|
# supporting information about them, but aren't actually for sale.
|
||||||
|
visible_object_data = (nc_page["render"] || []).
|
||||||
|
map { |id| object_data[id.to_s] }.
|
||||||
|
filter(&:present?)
|
||||||
|
|
||||||
|
items = visible_object_data.map do |item_info|
|
||||||
{
|
{
|
||||||
id: item_info["id"],
|
id: item_info["id"],
|
||||||
name: item_info["name"],
|
name: item_info["name"],
|
||||||
|
|
|
@ -54,7 +54,25 @@ module RocketAMFExtensions
|
||||||
raise RocketAMF::AMFError.new(first_message_data)
|
raise RocketAMF::AMFError.new(first_message_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
# HACK: It seems to me that these messages come back with Windows-1250
|
||||||
|
# (or similar) encoding on the strings? I'm basing this on the
|
||||||
|
# Patchwork Staff item, whose description arrives as:
|
||||||
|
#
|
||||||
|
# "That staff is cute, but dont use it as a walking stick \x96 I " +
|
||||||
|
# "dont think it will hold you up!"
|
||||||
|
#
|
||||||
|
# And the `\x96` is meant to represent an endash, which it doesn't in
|
||||||
|
# UTF-8 or in most extended ASCII encodings, but *does* in Windows's
|
||||||
|
# specific extended ASCII.
|
||||||
|
#
|
||||||
|
# Idk if this is something to do with the AMFPHP spec or how the AMFPHP
|
||||||
|
# server code they use serializes strings (I couldn't find any
|
||||||
|
# reference to it?), or just their internal database encoding being
|
||||||
|
# passed along as-is, or what? But this seems to be the most correct
|
||||||
|
# interpretation I know how to do, so, let's do it!
|
||||||
|
result.messages[0].data.body.tap do |body|
|
||||||
|
reencode_strings! body, "Windows-1250", "UTF-8"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -86,6 +104,16 @@ module RocketAMFExtensions
|
||||||
raise ConnectionError, e.message
|
raise ConnectionError, e.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reencode_strings!(target, from, to)
|
||||||
|
if target.is_a? String
|
||||||
|
target.force_encoding(from).encode!(to)
|
||||||
|
elsif target.is_a? Array
|
||||||
|
target.each { |x| reencode_strings!(x, from, to) }
|
||||||
|
elsif target.is_a? Hash
|
||||||
|
target.values.each { |x| reencode_strings!(x, from, to) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ConnectionError < RuntimeError
|
class ConnectionError < RuntimeError
|
||||||
|
|
59
public/503.html
Normal file
59
public/503.html
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Dress to Impress: Whelmy mode!</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: #fff;
|
||||||
|
color: #666;
|
||||||
|
font-family: arial, sans-serif;
|
||||||
|
padding: 2em 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
margin-inline: auto;
|
||||||
|
padding: 1em;
|
||||||
|
max-width: 600px;
|
||||||
|
|
||||||
|
display: grid;
|
||||||
|
grid-template-areas: "illustration body";
|
||||||
|
grid-template-columns: auto 1fr;
|
||||||
|
column-gap: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.5em;
|
||||||
|
margin: 0;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<img
|
||||||
|
width="100"
|
||||||
|
height="100"
|
||||||
|
alt="Distressed Grundo programmer"
|
||||||
|
src="/images/error-grundo.png"
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<h1>DTI is overloaded!</h1>
|
||||||
|
<p>
|
||||||
|
There's a lot going on in our server right now… usually this lasts for
|
||||||
|
a few seconds, then passes? Sorry about this!
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If this keeps happening, we'll be alerted automatically, and we'll do
|
||||||
|
our best to get it fixed up 💖
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue