mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-03-22 12:16:15 +00:00
More work on network handling refactor
This commit is contained in:
14
lib/cache.rb
14
lib/cache.rb
@@ -9,19 +9,17 @@ class W3DHub
|
||||
end
|
||||
|
||||
# Fetch a generic uri
|
||||
def self.fetch(uri:, force_fetch: false, async: true, backend: :w3dhub)
|
||||
def self.fetch(uri:, force_fetch: false, backend: :w3dhub)
|
||||
path = path(uri)
|
||||
|
||||
if !force_fetch && File.exist?(path)
|
||||
path
|
||||
elsif async
|
||||
BackgroundWorker.job(
|
||||
-> { Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend) },
|
||||
->(response) { File.open(path, "wb") { |f| f.write response.body } if response.status == 200 }
|
||||
)
|
||||
else
|
||||
response = Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend)
|
||||
File.open(path, "wb") { |f| f.write response.body } if response.status == 200
|
||||
Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend) do |result|
|
||||
if result.okay?
|
||||
File.open(path, "wb") { |f| f.write result.data }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user