Fix inconsistent indentation in swf_assets.rake
My editor now flags this stuff better, thank you editor!
This commit is contained in:
parent
2cc46703b9
commit
f6cece9a59
2 changed files with 25 additions and 31 deletions
|
@ -1,4 +1,3 @@
|
|||
require "addressable/template"
|
||||
require "addressable/uri"
|
||||
require "httparty"
|
||||
require "json"
|
||||
|
@ -15,12 +14,7 @@ module NeopetsMediaArchive
|
|||
include HTTParty
|
||||
base_uri "https://images.neopets.com/"
|
||||
|
||||
OLD_MANIFEST_PATH_TEMPLATE = Addressable::Template.new(
|
||||
"https://images.neopets.com/cp/{short_type}/data/{id1}/{id2}/{id3}/{id}_{hash}/manifest.json"
|
||||
)
|
||||
NEW_MANIFEST_PATH_TEMPLATE = Addressable::Template.new(
|
||||
"https://images.neopets.com/cp/{short_type}/data/{id1}/{id2}/{id3}/{id}/manifest.json"
|
||||
)
|
||||
ROOT_PATH = Pathname.new(Rails.configuration.neopets_media_archive_root)
|
||||
|
||||
# Load the file from the given `images.neopets.com` URI, as JSON.
|
||||
def self.load_json(uri)
|
||||
|
@ -102,7 +96,7 @@ module NeopetsMediaArchive
|
|||
end
|
||||
|
||||
def self.local_file_path(uri)
|
||||
Rails.configuration.neopets_media_archive_root + path_within_archive(uri)
|
||||
ROOT_PATH + path_within_archive(uri)
|
||||
end
|
||||
|
||||
class NotFound < StandardError; end
|
||||
|
|
|
@ -112,29 +112,29 @@ end
|
|||
|
||||
SWF_URL_PATTERN = %r{^(?:https?:)?//images\.neopets\.com/cp/(bio|items)/swf/(.+?)_([a-z0-9]+)\.swf$}
|
||||
def infer_manifest_url(swf_url, internet)
|
||||
url_match = swf_url.match(SWF_URL_PATTERN)
|
||||
raise ArgumentError, "not a valid SWF URL: #{swf_url}" if url_match.nil?
|
||||
url_match = swf_url.match(SWF_URL_PATTERN)
|
||||
raise ArgumentError, "not a valid SWF URL: #{swf_url}" if url_match.nil?
|
||||
|
||||
# Build the potential manifest URLs, from the two structures we know of.
|
||||
type, folders, hash_str = url_match.captures
|
||||
potential_manifest_urls = [
|
||||
"https://images.neopets.com/cp/#{type}/data/#{folders}/manifest.json",
|
||||
"https://images.neopets.com/cp/#{type}/data/#{folders}_#{hash_str}/manifest.json",
|
||||
]
|
||||
# Build the potential manifest URLs, from the two structures we know of.
|
||||
type, folders, hash_str = url_match.captures
|
||||
potential_manifest_urls = [
|
||||
"https://images.neopets.com/cp/#{type}/data/#{folders}/manifest.json",
|
||||
"https://images.neopets.com/cp/#{type}/data/#{folders}_#{hash_str}/manifest.json",
|
||||
]
|
||||
|
||||
# Send a HEAD request to test each manifest URL, without downloading its
|
||||
# content. If it succeeds, we're done!
|
||||
potential_manifest_urls.each do |potential_manifest_url|
|
||||
res = internet.head potential_manifest_url
|
||||
if res.ok?
|
||||
return potential_manifest_url
|
||||
elsif res.status == 404
|
||||
next # Ok, this was not the manifest!
|
||||
else
|
||||
raise "unexpected manifest response code: #{res.status}"
|
||||
end
|
||||
end
|
||||
# Send a HEAD request to test each manifest URL, without downloading its
|
||||
# content. If it succeeds, we're done!
|
||||
potential_manifest_urls.each do |potential_manifest_url|
|
||||
res = internet.head potential_manifest_url
|
||||
if res.ok?
|
||||
return potential_manifest_url
|
||||
elsif res.status == 404
|
||||
next # Ok, this was not the manifest!
|
||||
else
|
||||
raise "unexpected manifest response code: #{res.status}"
|
||||
end
|
||||
end
|
||||
|
||||
# Otherwise, there's no valid manifest URL.
|
||||
raise "all of the common manifest URL patterns returned HTTP 404"
|
||||
# Otherwise, there's no valid manifest URL.
|
||||
raise "all of the common manifest URL patterns returned HTTP 404"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue