Support downloading packages from upstream

This commit is contained in:
2026-11-04 19:54:44 -06:00
parent 4b95fcdf15
commit 3a15789a29
2 changed files with 33 additions and 6 deletions

View File

@@ -288,8 +288,19 @@ module W3DHubLauncher
end end
end end
else else
# TODO xD @worker.w3dhub_api.fetch_package(pkg, path: file_path, range: partially_valid_at) do |downloaded_bytes, total_downloaded_bytes, content_length|
@worker.w3dhub_api.fetch_package("TODO") sample_downloaded_bytes += downloaded_bytes
total_data_downloaded_bytes += downloaded_bytes
if Gosu.milliseconds - last_sample_time_ms >= 1_000
last_sample_time_ms = Gosu.milliseconds
fraction = (total_downloaded_bytes + partially_valid_at) / pkg.file_size.to_f
update_stage_progress(label: "Downloading #{W3DHubLauncher.format_size(total_data_downloaded_bytes)} / #{W3DHubLauncher.format_size(total_data_to_download_bytes)} [#{W3DHubLauncher.format_size(sample_downloaded_bytes)}/s]", fraction: (i.to_f + fraction) / manifest_packages.size)
sample_downloaded_bytes = 0
end
end
end end
abort_task!("Failed to download required package: #{pkg.name}:#{pkg.version} (#{result.error})") unless result.okay? abort_task!("Failed to download required package: #{pkg.name}:#{pkg.version} (#{result.error})") unless result.okay?
@@ -530,8 +541,7 @@ module W3DHubLauncher
result = if manifest_package.download_url result = if manifest_package.download_url
@worker.w3dhub_api.download(manifest_package.download_url, path: file_path) @worker.w3dhub_api.download(manifest_package.download_url, path: file_path)
else else
# TODO xD @worker.w3dhub_api.fetch_package(manifest_package, path: file_path)
@worker.w3dhub_api.fetch_package("TODO")
end end
if result.okay? if result.okay?

View File

@@ -82,6 +82,8 @@ module W3DHubLauncher
end end
result.data = true result.data = true
else
result.error = response.read
end end
rescue StandardError => e rescue StandardError => e
result.error = e result.error = e
@@ -265,8 +267,23 @@ module W3DHubLauncher
fetch("#{@access_token ? PRIMARY_W3DHUB_API_ENDPOINT : ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-package-details", method: :post, body: body, headers: headers(form_encoded: true)) fetch("#{@access_token ? PRIMARY_W3DHUB_API_ENDPOINT : ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-package-details", method: :post, body: body, headers: headers(form_encoded: true))
end end
def download_package() def fetch_package(manifest_package, path:, range: 0)
download() body = URI.encode_www_form(
"data": JSON.dump({
category: manifest_package.category,
subcategory: manifest_package.subcategory,
name: manifest_package.name,
version: manifest_package.version
})
)
download(
"#{W3DHubApi::PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-package",
path: path,
method: :post,
body: body,
headers: headers(form_encoded: true, range: range <= 0 ? nil : range)
)
end end
end end
end end