Brought back Excon for package downloading as the method recommended by async-http is unreliable, added support for importing games, repairer and updater tasks are both now simple subclasses of installer, implemented verify_files for checking installed files to prune download package list (currently causes Api.package_details to fail..., so disabled for now), misc. changes.

This commit is contained in:
2021-12-28 17:55:40 -06:00
parent f4aa666386
commit 82add3cc9d
12 changed files with 221 additions and 132 deletions

View File

@@ -2,7 +2,8 @@ class W3DHub
class Api
USER_AGENT = "Cyberarm's Linux Friendly W3D Hub Launcher v#{W3DHub::VERSION}".freeze
DEFAULT_HEADERS = [
["User-Agent", USER_AGENT]
["User-Agent", USER_AGENT],
["Accept", "application/json"]
].freeze
FORM_ENCODED_HEADERS = (
DEFAULT_HEADERS + [["Content-Type", "application/x-www-form-urlencoded"]]
@@ -126,15 +127,14 @@ class W3DHub
# /apis/launcher/1/get-package-details
# client requests package details: data={"packages":[{"category":"games","name":"apb.ico","subcategory":"apb","version":""}]}
def self.package_details(internet, packages)
body = "data=#{JSON.dump({ packages: packages })}"
body = URI.encode_www_form("data": JSON.dump({ packages: packages }))
response = internet.post("#{ENDPOINT}/apis/launcher/1/get-package-details", FORM_ENCODED_HEADERS, body)
if response.success?
hash = JSON.parse(response.read, symbolize_names: true)
packages = hash[:packages].map { |pkg| Package.new(pkg) }
return packages.first if packages.size == 1
return packages
hash[:packages].map { |pkg| Package.new(pkg) }
else
pp response, body
false
end
end