activestorage-aliyun 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +30 -7
- data/lib/active_storage/service/aliyun_service.rb +18 -6
- data/lib/active_storage_aliyun/version.rb +1 -1
- data/lib/activestorage-aliyun.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8561c1bab22046a3249849fa1198ecbdc6929b1f
|
4
|
+
data.tar.gz: 78758224fd12173075a2b3d79a5896d0361d43d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a137d16f6ddf427e374e92d951bd074dc1647e74c226a06d82ce8a4870e68b98653ea2d07b1ebd6a54586aca98d8d1ebdb684341368e8f9c3448adf5901e2f2
|
7
|
+
data.tar.gz: 8db2b3039051f23371d88c7f556f7ae39d12b75a39a7bd419b37630616d370a296daefb776fdbc59d73521158e2da1936e343079fd43a7286d25f47110d4006d
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# ActiveStorage Aliyun Service
|
2
|
+
|
3
|
+
Wraps the Aliyun OSS as an Active Storage service.
|
4
|
+
|
5
|
+
|
6
|
+
[](https://badge.fury.io/rb/activestorage-aliyun) [](https://travis-ci.org/huacnlee/activestorage-aliyun) [](https://codeclimate.com/github/huacnlee/activestorage-aliyun) [](https://codecov.io/github/huacnlee/activestorage-aliyun?branch=master)
|
3
7
|
|
4
|
-
## Usage
|
5
|
-
How to use my plugin.
|
6
8
|
|
7
9
|
## Installation
|
10
|
+
|
8
11
|
Add this line to your application's Gemfile:
|
9
12
|
|
10
13
|
```ruby
|
@@ -12,17 +15,37 @@ gem 'activestorage-aliyun'
|
|
12
15
|
```
|
13
16
|
|
14
17
|
And then execute:
|
18
|
+
|
15
19
|
```bash
|
16
20
|
$ bundle
|
17
21
|
```
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
config/storage.yml
|
26
|
+
|
27
|
+
```rb
|
28
|
+
production:
|
29
|
+
service: Aliyun
|
30
|
+
access_key_id: "your-oss-access-key-id"
|
31
|
+
access_key_secret: "your-oss-access-key-secret"
|
32
|
+
bucket: "bucket-name"
|
33
|
+
endpoint: "https://oss-cn-beijing.aliyuncs.com"
|
34
|
+
# path prefix, default: /
|
35
|
+
path: "my-app-files"
|
36
|
+
```
|
37
|
+
|
38
|
+
Use image:
|
39
|
+
|
40
|
+
```erb
|
41
|
+
- Orignial File URL: <%= image_tag @photo.image.service_url %>
|
42
|
+
- Thumb with OSS image service: <%= image_tag @photo.image.service_url(filename: 'x-oss-process=image/resize,h_100,w_100') %>
|
22
43
|
```
|
23
44
|
|
24
45
|
## Contributing
|
46
|
+
|
25
47
|
Contribution directions go here.
|
26
48
|
|
27
49
|
## License
|
50
|
+
|
28
51
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "aliyun/oss"
|
3
|
+
|
3
4
|
module ActiveStorage
|
4
5
|
class Service::AliyunService < Service
|
5
6
|
def initialize(**config)
|
@@ -8,15 +9,24 @@ module ActiveStorage
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def upload(key, io, checksum: nil)
|
11
|
-
headers = {}
|
12
12
|
instrument :upload, key: key, checksum: checksum do
|
13
|
-
bucket.put_object(path_for(key)
|
13
|
+
bucket.put_object(path_for(key)) do |stream|
|
14
|
+
stream << io.read
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def download(key)
|
18
20
|
instrument :download, key: key do
|
19
|
-
|
21
|
+
chunk_buff = []
|
22
|
+
bucket.get_object(path_for(key)) do |chunk|
|
23
|
+
if block_given?
|
24
|
+
yield chunk
|
25
|
+
else
|
26
|
+
chunk_buff << chunk
|
27
|
+
end
|
28
|
+
end
|
29
|
+
chunk_buff.join("")
|
20
30
|
end
|
21
31
|
end
|
22
32
|
|
@@ -28,7 +38,9 @@ module ActiveStorage
|
|
28
38
|
|
29
39
|
def delete_prefixed(prefix)
|
30
40
|
instrument :delete_prefixed, prefix: prefix do
|
31
|
-
bucket.
|
41
|
+
files = bucket.list_objects(prefix: path_for(prefix))
|
42
|
+
keys = files.map(&:key)
|
43
|
+
bucket.batch_delete_objects(keys, quiet: true)
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
@@ -42,7 +54,7 @@ module ActiveStorage
|
|
42
54
|
instrument :url, key: key do |payload|
|
43
55
|
generated_url = bucket.object_url(path_for(key), false, expires_in)
|
44
56
|
generated_url.gsub('http://', 'https://')
|
45
|
-
if filename.present?
|
57
|
+
if filename.present? && filename.include?("x-oss-process")
|
46
58
|
generated_url = [generated_url, filename].join("?")
|
47
59
|
end
|
48
60
|
|
@@ -82,7 +94,7 @@ module ActiveStorage
|
|
82
94
|
end
|
83
95
|
|
84
96
|
def client
|
85
|
-
@client ||=
|
97
|
+
@client ||= Aliyun::OSS::Client.new(
|
86
98
|
endpoint: endpoint,
|
87
99
|
access_key_id: config.fetch(:access_key_id),
|
88
100
|
access_key_secret: config.fetch(:access_key_secret),
|
data/lib/activestorage-aliyun.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
@@ -44,6 +44,7 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- CHANGELOG.md
|
47
48
|
- README.md
|
48
49
|
- Rakefile
|
49
50
|
- lib/active_storage/service/aliyun_service.rb
|