s3_assets_uploader 0.1.0 → 0.5.0
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 +5 -5
- data/.travis.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/README.md +27 -0
- data/lib/s3_assets_uploader/config.rb +26 -2
- data/lib/s3_assets_uploader/uploader.rb +18 -0
- data/lib/s3_assets_uploader/version.rb +1 -1
- data/s3_assets_uploader.gemspec +2 -1
- metadata +23 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ef7284ec8a4e6f67ef449bd755accb7f66409512f856eb6c99056320167f528
|
4
|
+
data.tar.gz: 36ba9f6e43677cea5b177fc1584ce0bdaf171c6a3347508bfcd6b0f350aef2d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7288f6c0a161604163656568303961e425d38a66e8a686019db4cbadf24c1f96197084db96a8c68b6901ab420a0eb8ad8fb141a754f7ce563497c3a190ab58fc
|
7
|
+
data.tar.gz: 0f5a3f7226a34edb70e95f0fca1e283496d82aedf76801136f3d6da0d786c6b656414ad07033201b8399b0f37f812c7e887d80b39df7b66bd965567c5c9a4454
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,19 @@
|
|
1
|
+
# 0.5.0
|
2
|
+
- Add `config.content_type` option
|
3
|
+
|
4
|
+
# 0.4.0
|
5
|
+
- Use aws-sdk v3
|
6
|
+
|
7
|
+
# 0.3.0
|
8
|
+
- Add `config.cache_control` option
|
9
|
+
- The default value is `max-age=2592000, public` .
|
10
|
+
|
11
|
+
# 0.2.0
|
12
|
+
- Now Content-Type is automatically specified from asset's filename.
|
13
|
+
- https://github.com/eagletmt/s3_assets_uploader/pull/2
|
14
|
+
|
15
|
+
# 0.1.1
|
16
|
+
- Add `config.additional_paths`
|
17
|
+
|
1
18
|
# 0.1.0
|
2
19
|
- Initial release
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# S3AssetsUploader
|
2
|
+
[](http://badge.fury.io/rb/s3_assets_uploader)
|
3
|
+
[](https://travis-ci.org/eagletmt/s3_assets_uploader)
|
2
4
|
|
3
5
|
Upload Rails assets to S3.
|
4
6
|
|
@@ -32,6 +34,31 @@ namespace :assets do
|
|
32
34
|
end
|
33
35
|
```
|
34
36
|
|
37
|
+
### Configurations
|
38
|
+
- `config.s3_client`
|
39
|
+
- Aws::S3::Client instance to upload files
|
40
|
+
- Default: `Aws::S3::Client.new`
|
41
|
+
- `config.bucket`
|
42
|
+
- S3 bucket name
|
43
|
+
- **Required**
|
44
|
+
- `config.assets_path`
|
45
|
+
- Local path to assets directory
|
46
|
+
- Default: `"public/assets"`
|
47
|
+
- `config.assets_prefix`
|
48
|
+
- Remote assets path prefix
|
49
|
+
- If set, public/assets/foo.png will be uploaded to `"#{assets_prefix}/assets/foo.png"`
|
50
|
+
- Default: `nil`
|
51
|
+
- `config.additional_paths`
|
52
|
+
- Additional directories to upload
|
53
|
+
- Default: `[]`
|
54
|
+
- `config.cache_control`
|
55
|
+
- cache_control option for S3
|
56
|
+
- Default: `"max-age=2592000, public"`
|
57
|
+
- `config.content_type`
|
58
|
+
- Set custom handler to determine content-type of the object
|
59
|
+
- When the handler returns nil, the content-type is guessed from its extension
|
60
|
+
- Default: `nil`
|
61
|
+
|
35
62
|
## Development
|
36
63
|
|
37
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,14 +1,18 @@
|
|
1
|
-
require 'aws-sdk'
|
1
|
+
require 'aws-sdk-s3'
|
2
2
|
|
3
3
|
module S3AssetsUploader
|
4
|
-
class Config < Struct.new(:s3_client, :bucket, :assets_path, :assets_prefix)
|
4
|
+
class Config < Struct.new(:s3_client, :bucket, :assets_path, :assets_prefix, :additional_paths, :cache_control, :content_type)
|
5
5
|
class ValidationError < StandardError
|
6
6
|
end
|
7
7
|
|
8
8
|
DEFAULT_ASSETS_PATH = 'public/assets'.freeze
|
9
|
+
DEFAULT_CACHE_CONTROL = 'max-age=2592000, public'
|
9
10
|
|
10
11
|
def initialize
|
11
12
|
self.assets_path = DEFAULT_ASSETS_PATH
|
13
|
+
self.cache_control = DEFAULT_CACHE_CONTROL
|
14
|
+
self.additional_paths = []
|
15
|
+
self.content_type = nil
|
12
16
|
end
|
13
17
|
|
14
18
|
def assets_path
|
@@ -23,14 +27,34 @@ module S3AssetsUploader
|
|
23
27
|
if bucket.nil?
|
24
28
|
raise ValidationError.new('config.bucket must be set')
|
25
29
|
end
|
30
|
+
additional_paths.each do |path|
|
31
|
+
assert_under_public_path!(path)
|
32
|
+
end
|
26
33
|
self.s3_client ||= create_default_client
|
27
34
|
true
|
28
35
|
end
|
29
36
|
|
37
|
+
def content_type(&block)
|
38
|
+
self[:content_type] = block
|
39
|
+
end
|
40
|
+
|
41
|
+
def guess_content_type(path)
|
42
|
+
return unless self[:content_type]
|
43
|
+
|
44
|
+
self[:content_type].call(path)
|
45
|
+
end
|
46
|
+
|
30
47
|
private
|
31
48
|
|
32
49
|
def create_default_client
|
33
50
|
Aws::S3::Client.new
|
34
51
|
end
|
52
|
+
|
53
|
+
def assert_under_public_path!(path)
|
54
|
+
if Pathname.new(path).relative_path_from(public_path).to_s.start_with?('../')
|
55
|
+
raise ValidationError.new("#{path} must be under #{public_path}")
|
56
|
+
end
|
57
|
+
true
|
58
|
+
end
|
35
59
|
end
|
36
60
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 's3_assets_uploader/config'
|
2
|
+
require 'mime/types'
|
2
3
|
|
3
4
|
module S3AssetsUploader
|
4
5
|
class Uploader
|
@@ -10,6 +11,9 @@ module S3AssetsUploader
|
|
10
11
|
|
11
12
|
def upload
|
12
13
|
upload_path(@config.assets_path)
|
14
|
+
@config.additional_paths.each do |path|
|
15
|
+
upload_path(Pathname.new(path))
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
private
|
@@ -25,6 +29,8 @@ module S3AssetsUploader
|
|
25
29
|
body: f,
|
26
30
|
bucket: @config.bucket,
|
27
31
|
key: compute_asset_key(path),
|
32
|
+
content_type: guess_content_type(path),
|
33
|
+
cache_control: @config.cache_control,
|
28
34
|
)
|
29
35
|
end
|
30
36
|
end
|
@@ -38,6 +44,18 @@ module S3AssetsUploader
|
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
47
|
+
def guess_content_type(path)
|
48
|
+
content_type = @config.guess_content_type(path)
|
49
|
+
return content_type if content_type
|
50
|
+
|
51
|
+
mime_type = MIME::Types.type_for(path.basename.to_s).first
|
52
|
+
if mime_type
|
53
|
+
mime_type.content_type
|
54
|
+
else
|
55
|
+
'application/octet-stream'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
41
59
|
def relative_path(path)
|
42
60
|
path.relative_path_from(@config.public_path)
|
43
61
|
end
|
data/s3_assets_uploader.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "aws-sdk", ">=
|
22
|
+
spec.add_dependency "aws-sdk-s3", ">= 1.0"
|
23
|
+
spec.add_dependency "mime-types"
|
23
24
|
spec.add_development_dependency "bundler"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "rspec", ">= 3.0"
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_assets_uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: aws-sdk
|
14
|
+
name: aws-sdk-s3
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mime-types
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +107,7 @@ homepage: https://github.com/eagletmt/s3_assets_uploader
|
|
93
107
|
licenses:
|
94
108
|
- MIT
|
95
109
|
metadata: {}
|
96
|
-
post_install_message:
|
110
|
+
post_install_message:
|
97
111
|
rdoc_options: []
|
98
112
|
require_paths:
|
99
113
|
- lib
|
@@ -108,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
122
|
- !ruby/object:Gem::Version
|
109
123
|
version: '0'
|
110
124
|
requirements: []
|
111
|
-
|
112
|
-
|
113
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.13
|
126
|
+
signing_key:
|
114
127
|
specification_version: 4
|
115
128
|
summary: Upload Rails assets to S3.
|
116
129
|
test_files: []
|