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 "addressable/uri"
|
||||||
require "httparty"
|
require "httparty"
|
||||||
require "json"
|
require "json"
|
||||||
|
@ -15,12 +14,7 @@ module NeopetsMediaArchive
|
||||||
include HTTParty
|
include HTTParty
|
||||||
base_uri "https://images.neopets.com/"
|
base_uri "https://images.neopets.com/"
|
||||||
|
|
||||||
OLD_MANIFEST_PATH_TEMPLATE = Addressable::Template.new(
|
ROOT_PATH = Pathname.new(Rails.configuration.neopets_media_archive_root)
|
||||||
"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"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Load the file from the given `images.neopets.com` URI, as JSON.
|
# Load the file from the given `images.neopets.com` URI, as JSON.
|
||||||
def self.load_json(uri)
|
def self.load_json(uri)
|
||||||
|
@ -102,7 +96,7 @@ module NeopetsMediaArchive
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.local_file_path(uri)
|
def self.local_file_path(uri)
|
||||||
Rails.configuration.neopets_media_archive_root + path_within_archive(uri)
|
ROOT_PATH + path_within_archive(uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
class NotFound < StandardError; 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$}
|
SWF_URL_PATTERN = %r{^(?:https?:)?//images\.neopets\.com/cp/(bio|items)/swf/(.+?)_([a-z0-9]+)\.swf$}
|
||||||
def infer_manifest_url(swf_url, internet)
|
def infer_manifest_url(swf_url, internet)
|
||||||
url_match = swf_url.match(SWF_URL_PATTERN)
|
url_match = swf_url.match(SWF_URL_PATTERN)
|
||||||
raise ArgumentError, "not a valid SWF URL: #{swf_url}" if url_match.nil?
|
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.
|
# Build the potential manifest URLs, from the two structures we know of.
|
||||||
type, folders, hash_str = url_match.captures
|
type, folders, hash_str = url_match.captures
|
||||||
potential_manifest_urls = [
|
potential_manifest_urls = [
|
||||||
"https://images.neopets.com/cp/#{type}/data/#{folders}/manifest.json",
|
"https://images.neopets.com/cp/#{type}/data/#{folders}/manifest.json",
|
||||||
"https://images.neopets.com/cp/#{type}/data/#{folders}_#{hash_str}/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
|
# Send a HEAD request to test each manifest URL, without downloading its
|
||||||
# content. If it succeeds, we're done!
|
# content. If it succeeds, we're done!
|
||||||
potential_manifest_urls.each do |potential_manifest_url|
|
potential_manifest_urls.each do |potential_manifest_url|
|
||||||
res = internet.head potential_manifest_url
|
res = internet.head potential_manifest_url
|
||||||
if res.ok?
|
if res.ok?
|
||||||
return potential_manifest_url
|
return potential_manifest_url
|
||||||
elsif res.status == 404
|
elsif res.status == 404
|
||||||
next # Ok, this was not the manifest!
|
next # Ok, this was not the manifest!
|
||||||
else
|
else
|
||||||
raise "unexpected manifest response code: #{res.status}"
|
raise "unexpected manifest response code: #{res.status}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Otherwise, there's no valid manifest URL.
|
# Otherwise, there's no valid manifest URL.
|
||||||
raise "all of the common manifest URL patterns returned HTTP 404"
|
raise "all of the common manifest URL patterns returned HTTP 404"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue