anaconda 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +29 -8
- data/lib/anaconda/anaconda_for.rb +13 -4
- data/lib/anaconda/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 911805ae124cc803fe5b8b0bb0a83d33f57bffe8
|
4
|
+
data.tar.gz: 9d0dab201af413c396fd6dd8f2a2bb53e4f67d12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c419a1acb382d201e2e92094cbfc06a075ca96bd7297dcf1e82c96e5b167dbf5c501874ffb4343aa7a3161b556a6074f71721bd9de6e122b777a63dc4679ab7d
|
7
|
+
data.tar.gz: 8638e2cc7119df3e65e3b1a8daff553d2e1862e2bf2d43333e158c962e1dc272182c014db1a19ef872f77ae6152c3c9b584b0d3412bd9c5b6fd2f8a281073285
|
data/README.markdown
CHANGED
@@ -134,8 +134,9 @@ We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](http
|
|
134
134
|
* `allowed_file_types` default: _all_
|
135
135
|
* `host` String. If specified, this will be used to access publically stored objects instead of the S3 bucket. Useful for CloudFront integration. Note: At this time privately stored objects will still be requested via S3. Default: _false_
|
136
136
|
* `protocol` `https`, `http`, or `:auto`. If `:auto`, `//` will be used as the protocol. Note: At this time, all privately stored objects are requested over https. Default: `http`
|
137
|
-
|
138
|
-
|
137
|
+
* `remove_previous_s3_files_on_change` Boolean. If true, files will be removed from S3 when a new file is uploaded. Default: `true`
|
138
|
+
* `remove_previous_s3_files_on_destroy` Boolean. If true, files will be removed from S3 when a record is destroyed. Default: `true`
|
139
|
+
* `expiry_length` - If supplied, this is the length in seconds that a signed URL is valid for. Default: `1.hour`
|
139
140
|
|
140
141
|
* Form setup
|
141
142
|
|
@@ -154,7 +155,7 @@ We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](http
|
|
154
155
|
* `upload_details_container` - An element id you would like the upload details located in. Defaults to `<resource>_<attribtue>_details` ex: `post_media_asset_details`
|
155
156
|
* `auto_upload` - If set to true, upload will begin as soon as a file is selected. Default: *false*
|
156
157
|
* `auto_submit` - If set to true, form will submit automatically when upload is completed. Useful when mixed with `auto_upload: true`, especially if the file field is the only field on the form. Default: *true* when auto_upload is false; *false* when auto_upload is true.
|
157
|
-
|
158
|
+
* `base_key` - If supplied, this will be the base_key used for this upload
|
158
159
|
|
159
160
|
* Fields
|
160
161
|
|
@@ -168,14 +169,30 @@ We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](http
|
|
168
169
|
* :asset_url
|
169
170
|
* :asset_download_url
|
170
171
|
|
171
|
-
The magic methods are asset_url and asset_download_url
|
172
|
+
The magic methods are `asset_url` and `asset_download_url`.
|
172
173
|
|
173
|
-
`asset_url` will return a signed S3 URL if the file is stored with an ACL of `private` and will return a non-signed URL if the file is stored with public access.
|
174
|
+
`asset_url` will return a signed S3 URL if the file is stored with an ACL of `private` and will return a non-signed URL if the file is stored with public access. This accepts a single optional hash argument with possible parameters `protocol` and `expires`.
|
174
175
|
|
175
|
-
|
176
|
+
`asset_download_url` will return a signed S3 URL with content-disposition set to attachment so the file will be downloaded instead of opened in the browser. This accepts a single optional hash argument. The only supported parameter in this hash is `expires`.
|
177
|
+
|
178
|
+
`protocol`, if specified here, will override the default value set in the model.
|
179
|
+
`expires` is a DateTime object when a signed URL will be valid until. On a file stored publically, this has no effect.
|
180
|
+
|
181
|
+
|
182
|
+
Example usages:
|
183
|
+
|
184
|
+
# Assuming the files are stored privately.
|
185
|
+
|
186
|
+
asset_url(expires: 3.hours.from_now)
|
187
|
+
# Generates a URL that is valid for 3 hours
|
188
|
+
|
189
|
+
asset_url(protocol: "https", expires: 5.minutes.from_now)
|
190
|
+
# Generates a URL that is valid for 5 minutes, and uses the https protocol
|
191
|
+
|
192
|
+
asset_download_url(expires: 5.minutes.from_now)
|
193
|
+
# Generates a URL that is valid for 5 minutes, and will cause the browser to download the object.
|
194
|
+
# This is most useful for things like images that most browsers try to display.
|
176
195
|
|
177
|
-
`asset_download_url` will return a signed S3 URL with content-disposition set to attachment so the file will be downloaded instead of opened in the browser.
|
178
|
-
|
179
196
|
### Advanced Usage
|
180
197
|
|
181
198
|
#### Events
|
@@ -202,6 +219,10 @@ If you return false to the following events it will prevent the default behavior
|
|
202
219
|
From version 1.0.0 on we have used [Semantic Versioning](http://semver.org/).
|
203
220
|
|
204
221
|
## Changelog
|
222
|
+
* 1.0.7
|
223
|
+
* Add support for `expires` option in signed AWS URLs.
|
224
|
+
* Add option for setting default `expiry_length` for signed AWS URLs.
|
225
|
+
|
205
226
|
* 1.0.6
|
206
227
|
* Loosen dependency requirement on `simple_form`
|
207
228
|
|
@@ -39,6 +39,7 @@ module Anaconda
|
|
39
39
|
base_key: "#{anaconda_column}_anaconda_default_base_key".to_sym,
|
40
40
|
host: false,
|
41
41
|
protocol: "http",
|
42
|
+
expiry_length: 1.hour,
|
42
43
|
remove_previous_s3_files_on_change: true,
|
43
44
|
remove_previous_s3_files_on_destroy: true
|
44
45
|
)
|
@@ -117,10 +118,10 @@ module Anaconda
|
|
117
118
|
options = args.extract_options!
|
118
119
|
logger.debug "Extracted Options:"
|
119
120
|
logger.debug(options)
|
120
|
-
|
121
|
+
|
121
122
|
if send("#{column_name}_stored_privately")
|
122
123
|
aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => Anaconda.aws[:aws_access_key], :aws_secret_access_key => Anaconda.aws[:aws_secret_key], :path_style => Anaconda.aws[:path_style]})
|
123
|
-
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"),
|
124
|
+
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"), anaconda_expiry_length(column_name, options[:expires]))
|
124
125
|
elsif self.anaconda_options[column_name.to_sym][:host]
|
125
126
|
"#{anaconda_protocol(column_name, options[:protocol])}#{self.anaconda_options[column_name.to_sym][:host]}/#{send("#{column_name}_file_path")}"
|
126
127
|
else
|
@@ -130,10 +131,13 @@ module Anaconda
|
|
130
131
|
|
131
132
|
def anaconda_download_url(column_name)
|
132
133
|
return nil unless send("#{column_name}_file_path").present?
|
134
|
+
options = args.extract_options!
|
135
|
+
logger.debug "Extracted Options:"
|
136
|
+
logger.debug(options)
|
133
137
|
|
134
|
-
|
138
|
+
aws_options = {query: {"response-content-disposition" => "attachment;"}}
|
135
139
|
aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => Anaconda.aws[:aws_access_key], :aws_secret_access_key => Anaconda.aws[:aws_secret_key], :path_style => Anaconda.aws[:path_style]})
|
136
|
-
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"),
|
140
|
+
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"), anaconda_expiry_length(column_name, options[:expires]), aws_options)
|
137
141
|
|
138
142
|
end
|
139
143
|
|
@@ -147,6 +151,11 @@ module Anaconda
|
|
147
151
|
end
|
148
152
|
end
|
149
153
|
|
154
|
+
def anaconda_expiry_length(column_name, override = nil)
|
155
|
+
return override if override
|
156
|
+
self.anaconda_options[column_name.to_sym][:expiry_length].seconds.from_now
|
157
|
+
end
|
158
|
+
|
150
159
|
def anaconda_default_base_key_for(column_name)
|
151
160
|
"#{self.class.to_s.pluralize.downcase}/#{column_name.to_s.pluralize}/#{(0...32).map{(65+rand(26)).chr}.join.downcase}"
|
152
161
|
end
|
data/lib/anaconda/version.rb
CHANGED