metanorma-release 0.2.19 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01147610e009c11c2192cd56b2aed8fc731c2c002a9d6e35f91c61045197fcfe
|
|
4
|
+
data.tar.gz: 54e3c27c6e5f06a3c310a12e2e20e51080df1ffb3d577ec5a1f378904fc59fa6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 294bfaa8b3772c8a4507c4168638b2aff9b2466592494ea68ed31abae6f205f41d038e0c9c946f7405711345921f9c6ae27e809d659e5b9b4485acc38850f6ca
|
|
7
|
+
data.tar.gz: '058a98333e8ee3506d93ed85d95a61a2c4a8316f53cebc85d2824968031a92b1b003b9bcbfcce697c42405e9f8a7e4061b343609b22ae22f6beed885f594dbba'
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "digest"
|
|
4
|
+
|
|
3
5
|
module Metanorma
|
|
4
6
|
module Release
|
|
5
7
|
module Platform
|
|
@@ -13,8 +15,9 @@ module Metanorma
|
|
|
13
15
|
class ReleaseFetcher
|
|
14
16
|
include Metanorma::Release::ReleaseFetcher
|
|
15
17
|
|
|
16
|
-
def initialize(client:)
|
|
18
|
+
def initialize(client:, download_cache_dir: nil)
|
|
17
19
|
@client = client
|
|
20
|
+
@download_cache_dir = download_cache_dir
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
def fetch(repo, etag: nil)
|
|
@@ -67,11 +70,28 @@ module Metanorma
|
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
def download_asset(url)
|
|
70
|
-
|
|
73
|
+
cache_path = cache_file_path(url)
|
|
74
|
+
if cache_path && File.exist?(cache_path)
|
|
75
|
+
return File.binread(cache_path)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
data = @client.get(url, accept: "application/octet-stream")
|
|
79
|
+
if cache_path && data
|
|
80
|
+
FileUtils.mkdir_p(File.dirname(cache_path))
|
|
81
|
+
File.binwrite(cache_path, data)
|
|
82
|
+
end
|
|
83
|
+
data
|
|
71
84
|
rescue StandardError => e
|
|
72
85
|
warn "Warning: Failed to download asset #{url}: #{e.message}"
|
|
73
86
|
nil
|
|
74
87
|
end
|
|
88
|
+
|
|
89
|
+
def cache_file_path(url)
|
|
90
|
+
return nil unless @download_cache_dir
|
|
91
|
+
|
|
92
|
+
hash = Digest::SHA256.hexdigest(url)
|
|
93
|
+
File.join(@download_cache_dir, hash)
|
|
94
|
+
end
|
|
75
95
|
end
|
|
76
96
|
end
|
|
77
97
|
end
|
|
@@ -31,9 +31,12 @@ module Metanorma
|
|
|
31
31
|
)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
download_cache = opts[:cache_dir] ? File.join(opts[:cache_dir], "downloads") : nil
|
|
35
|
+
|
|
34
36
|
{
|
|
35
37
|
discoverer: discoverer,
|
|
36
|
-
fetcher: Platform::GitHub::ReleaseFetcher.new(client: client
|
|
38
|
+
fetcher: Platform::GitHub::ReleaseFetcher.new(client: client,
|
|
39
|
+
download_cache_dir: download_cache),
|
|
37
40
|
manifest_reader: Platform::GitHub::ManifestReader.new(client: client),
|
|
38
41
|
}
|
|
39
42
|
},
|