carrierwave-aws 1.3.0 → 1.4.0

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
- SHA1:
3
- metadata.gz: b08e5e5ca8483cb1079391083b6da62061a0552d
4
- data.tar.gz: 1044c413b9168267762ba1a3b862bb3eaa32e6c9
2
+ SHA256:
3
+ metadata.gz: df1b2dd13c2fe5d10191144d8a709b4669783478e51cd099d516b9df8fa70fa1
4
+ data.tar.gz: 272ee0bea417ba78fae9ea98b4ec87a89483d8c7308630c6489cccf722442385
5
5
  SHA512:
6
- metadata.gz: 3d62d9d5fd5ecdb09df295da2eac7b6d6398ccf76384c1b0eb94405fb003136e351c16d83233f92d51a88d61944aee83e9672f01e197137bf512dbbdc3f17547
7
- data.tar.gz: e0ebf6479be16ee6d41082cbcd0034b33c54c1fbc95403fb7494a72f0fcdf4166116ce83632ef9f1e5c3a04936839aa77582773c1eecc00af458284b86a92abd
6
+ metadata.gz: ed978e69ba5751cb793fa2c63afd075c6c8e4a608de7d36999a0b9c5a8b06e4aaf42391ec211d98d21186e402cb147bf39629de28e328bf51e64c156b88fffa9
7
+ data.tar.gz: '09961c9485558f613c1ce426812375b2f30d87e91042675dc3021a8dfa98c5be2a24959fa234276c55ac1612c5b4515a2674b57717cb7314b96b8e54cea552c4'
@@ -29,6 +29,7 @@ module CarrierWave
29
29
  add_config :aws_write_options
30
30
  add_config :aws_acl
31
31
  add_config :aws_signer
32
+ add_config :asset_host_public
32
33
 
33
34
  configure do |config|
34
35
  config.storage_engines[:aws] = 'CarrierWave::Storage::AWS'
@@ -83,6 +84,10 @@ module CarrierWave
83
84
  self.class.aws_signer
84
85
  end
85
86
  end
87
+
88
+ def asset_host_public
89
+ @asset_host_public || false
90
+ end
86
91
  end
87
92
  end
88
93
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Carrierwave
4
4
  module AWS
5
- VERSION = '1.3.0'
5
+ VERSION = '1.4.0'
6
6
  end
7
7
  end
@@ -62,15 +62,15 @@ module CarrierWave
62
62
 
63
63
  def copy_to(new_path)
64
64
  bucket.object(new_path).copy_from(
65
- copy_source: "#{bucket.name}/#{file.key}",
66
- acl: uploader.aws_acl
65
+ "#{bucket.name}/#{file.key}",
66
+ aws_options.copy_options(self)
67
67
  )
68
68
  end
69
69
 
70
70
  def move_to(new_path)
71
71
  file.move_to(
72
72
  "#{bucket.name}/#{new_path}",
73
- acl: uploader.aws_acl
73
+ aws_options.move_options(self)
74
74
  )
75
75
  end
76
76
 
@@ -84,7 +84,7 @@ module CarrierWave
84
84
 
85
85
  def public_url
86
86
  if uploader.asset_host
87
- "#{uploader.asset_host}/#{path}"
87
+ "#{uploader.asset_host}/#{uri_path}"
88
88
  else
89
89
  file.public_url.to_s
90
90
  end
@@ -93,10 +93,10 @@ module CarrierWave
93
93
  def url(options = {})
94
94
  if signer
95
95
  signed_url(options)
96
- elsif uploader.aws_acl.to_s != 'public-read'
97
- authenticated_url(options)
98
- else
96
+ elsif public?
99
97
  public_url
98
+ else
99
+ authenticated_url(options)
100
100
  end
101
101
  end
102
102
 
@@ -109,6 +109,14 @@ module CarrierWave
109
109
  def signer
110
110
  uploader.aws_signer
111
111
  end
112
+
113
+ def uri_path
114
+ path.gsub(%r{[^/]+}) { |segment| Seahorse::Util.uri_escape(segment) }
115
+ end
116
+
117
+ def public?
118
+ uploader.aws_acl.to_s == 'public-read' || uploader.asset_host_public
119
+ end
112
120
  end
113
121
  end
114
122
  end
@@ -3,6 +3,8 @@
3
3
  module CarrierWave
4
4
  module Storage
5
5
  class AWSOptions
6
+ MULTIPART_TRESHOLD = 15 * 1024 * 1024
7
+
6
8
  attr_reader :uploader
7
9
 
8
10
  def initialize(uploader)
@@ -21,6 +23,14 @@ module CarrierWave
21
23
  }.merge(aws_attributes).merge(aws_write_options)
22
24
  end
23
25
 
26
+ def move_options(file)
27
+ {
28
+ acl: uploader.aws_acl,
29
+ multipart_copy: file.size >= MULTIPART_TRESHOLD
30
+ }.merge(aws_attributes).merge(aws_write_options)
31
+ end
32
+ alias copy_options move_options
33
+
24
34
  def expiration_options(options = {})
25
35
  uploader_expiration = uploader.aws_authenticated_url_expiration
26
36
 
@@ -30,7 +40,9 @@ module CarrierWave
30
40
  private
31
41
 
32
42
  def aws_attributes
33
- uploader.aws_attributes || {}
43
+ attributes = uploader.aws_attributes
44
+ return {} if attributes.nil?
45
+ attributes.respond_to?(:call) ? attributes.call : attributes
34
46
  end
35
47
 
36
48
  def aws_read_options
@@ -72,9 +72,19 @@ describe CarrierWave::Storage::AWSFile do
72
72
  aws_file.url
73
73
  end
74
74
 
75
+ it 'requests a public url if asset_host_public' do
76
+ allow(uploader).to receive(:aws_acl) { :'authenticated-read' }
77
+ allow(uploader).to receive(:asset_host_public) { true }
78
+
79
+ expect(file).to receive(:public_url)
80
+
81
+ aws_file.url
82
+ end
83
+
75
84
  it 'requests an authenticated url if acl is not public readable' do
76
85
  allow(uploader).to receive(:aws_acl) { :private }
77
86
  allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
87
+ allow(uploader).to receive(:asset_host_public) { false }
78
88
 
79
89
  expect(file).to receive(:presigned_url).with(:get, expires_in: 60)
80
90
 
@@ -126,4 +136,12 @@ describe CarrierWave::Storage::AWSFile do
126
136
  end
127
137
  end
128
138
  end
139
+
140
+ describe '#public_url' do
141
+ it 'uri-encodes the path' do
142
+ allow(uploader).to receive(:asset_host) { 'http://example.com' }
143
+ aws_file.path = 'uploads/images/jekyll+and+hyde.txt'
144
+ expect(aws_file.public_url).to eq 'http://example.com/uploads/images/jekyll%2Band%2Bhyde.txt'
145
+ end
146
+ end
129
147
  end
@@ -52,6 +52,14 @@ describe CarrierWave::Storage::AWSOptions do
52
52
  expect { options.write_options(file) }.to_not raise_error
53
53
  end
54
54
 
55
+ it 'works if aws_attributes is a Proc' do
56
+ expect(uploader).to receive(:aws_attributes).and_return(
57
+ -> { { expires: 1.week.from_now.httpdate } }
58
+ )
59
+
60
+ expect { options.write_options(file) }.to_not raise_error
61
+ end
62
+
55
63
  it 'works if aws_write_options is nil' do
56
64
  expect(uploader).to receive(:aws_write_options) { nil }
57
65
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2019-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.7'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.0'
22
+ version: '2.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.7'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.0'
32
+ version: '2.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: aws-sdk-s3
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -114,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.5.2.1
117
+ rubygems_version: 3.0.1
119
118
  signing_key:
120
119
  specification_version: 4
121
120
  summary: Native aws-sdk support for S3 in CarrierWave