browse-everything 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bd89b5a4d99d1d4d288de7ea1f2d169b1d65052
4
- data.tar.gz: b75cd73ebf3bac49970c4f5de27def245039557e
3
+ metadata.gz: bdca52f24c726e1a0a0b04200f2ec65359b3b16b
4
+ data.tar.gz: 181729d5c03b8c06773cbe1f2797e471ccaac5de
5
5
  SHA512:
6
- metadata.gz: de5b0b8a4626e22d166a1d90143e7c2c2ba7c59a15db9cc6f770c8929c4efaadcdcf8df7de09a5f1c55524b9d60c6e8e7f7198db394893eba42ad22e6d88dd1b
7
- data.tar.gz: a6c7b57568667806cdc534e3fc5d7b939382c63cc509bb83b7f25e3c8ec07a81719209b59dcb2551f84b5a792fd73acefb09fe14deecbd18802b932cf5549bff
6
+ metadata.gz: 454cadb16e026a647559e5759042aeeaa04e724733053ea6f3215ec13bd4d35cca202249ac75b6b51f53e270a77dc9008065179f0b4e5c3913a6a64a2772af29
7
+ data.tar.gz: 4b4ce4d14208a57d43ec2462c96253f1a04c6546c40496bea0ab7c6450ddbbc997624035d30c18052d81a0c7db6e145877d13e8338863316febd624bea7c3199
@@ -9,7 +9,7 @@
9
9
  </tr>
10
10
  </thead>
11
11
  <% provider.contents(browse_path).each_with_index do |file, index| %>
12
- <% next if file.relative_parent_path? %>
12
+ <% next if file.relative_parent_path? or file.size.nil? %>
13
13
  <%= render :partial => 'file', :locals => { :file => file, :index => index,
14
14
  :path => browse_everything_engine.contents_path(provider_name, file.id), :parent => params[:parent] } %>
15
15
  <% end %>
@@ -26,38 +26,68 @@ module BrowseEverything
26
26
  target
27
27
  end
28
28
 
29
- def retrieve(spec)
29
+ def retrieve(spec, &block)
30
30
  if spec.key?('expires') && Time.parse(spec['expires']) < Time.now
31
31
  raise ArgumentError, "Download spec expired at #{spec['expires']}"
32
32
  end
33
33
 
34
- url = ::Addressable::URI.parse(spec['url'])
35
- file_size = spec.fetch('file_size', 0).to_i
36
- retrieved = 0
37
- case url.scheme
34
+ parsed_spec = parse_spec(spec)
35
+
36
+ case parsed_spec[:url].scheme
38
37
  when 'file'
39
- File.open(url.path, 'rb') do |f|
38
+ retrieve_file(parsed_spec, &block)
39
+ when /https?/
40
+ retrieve_http(parsed_spec, &block)
41
+ else
42
+ raise URI::BadURIError, "Unknown URI scheme: #{parsed_spec[:url].scheme}"
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def parse_spec(spec)
49
+ result = {
50
+ url: ::Addressable::URI.parse(spec['url']),
51
+ headers: spec['auth_header'] || {},
52
+ file_size: spec.fetch('file_size', 0).to_i
53
+ }
54
+
55
+ result[:headers].each_pair { |k, v| result[:headers][k] = v.tr('+', ' ') }
56
+ result[:file_size] = get_file_size(result) if result[:file_size] < 1
57
+ result
58
+ end
59
+
60
+ def retrieve_file(parsed_spec)
61
+ retrieved = 0
62
+ File.open(parsed_spec[:url].path, 'rb') do |f|
40
63
  until f.eof?
41
64
  chunk = f.read(chunk_size)
42
65
  retrieved += chunk.length
43
- yield(chunk, retrieved, file_size)
66
+ yield(chunk, retrieved, parsed_spec[:file_size])
44
67
  end
45
68
  end
46
- when /https?/
47
- headers = spec['auth_header'] || {}
48
- headers.each_pair do |k, v|
49
- headers[k] = v.tr('+', ' ')
50
- end
69
+ end
51
70
 
52
- stream_body = file_size > 500.megabytes
71
+ def retrieve_http(parsed_spec)
72
+ retrieved = 0
73
+ stream_body = parsed_spec[:file_size] > 500.megabytes
53
74
 
54
- HTTParty.get(url.to_s, stream_body: stream_body, headers: headers) do |chunk|
75
+ HTTParty.get(parsed_spec[:url].to_s, stream_body: stream_body, headers: parsed_spec[:headers]) do |chunk|
55
76
  retrieved += chunk.length
56
- yield(chunk, retrieved, file_size)
77
+ yield(chunk, retrieved, parsed_spec[:file_size])
78
+ end
79
+ end
80
+
81
+ def get_file_size(parsed_spec)
82
+ case parsed_spec[:url].scheme
83
+ when 'file'
84
+ File.size(url.path)
85
+ when /https?/
86
+ response = HTTParty.head(parsed_spec[:url].to_s, headers: parsed_spec[:headers])
87
+ response.content_length
88
+ else
89
+ raise URI::BadURIError, "Unknown URI scheme: #{url.scheme}"
57
90
  end
58
- else
59
- raise URI::BadURIError, "Unknown URI scheme: #{url.scheme}"
60
91
  end
61
- end
62
92
  end
63
93
  end
@@ -1,3 +1,3 @@
1
1
  module BrowseEverything
2
- VERSION = '0.14.1'.freeze
2
+ VERSION = '0.14.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browse-everything
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carolyn Cole
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-09-11 00:00:00.000000000 Z
16
+ date: 2017-09-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rails