activestorage-aliyun 0.1.0 → 0.1.1

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: 280e83ae1965f9a922c30d70f38be9ed550abaa4
4
- data.tar.gz: b6c1f47cf9f9445309f7efe09578047396fdde37
3
+ metadata.gz: 8561c1bab22046a3249849fa1198ecbdc6929b1f
4
+ data.tar.gz: 78758224fd12173075a2b3d79a5896d0361d43d1
5
5
  SHA512:
6
- metadata.gz: 7e6c52b08d031f69fb05fa444edf7906ea76a18267874e0043caceb6c53127454a357c98cf759cfc16b1215e453893331ffb1970972412f6b6c8b2767fe7a51d
7
- data.tar.gz: 55fc172b6b021a02f8aa3f7096a2f2de9324008c0c3e12080ca22f02bbe53a85fcb65ba245fe8572b94ee85224f64c9b1e6d5d47c49c83ad44cf2424136115b1
6
+ metadata.gz: 0a137d16f6ddf427e374e92d951bd074dc1647e74c226a06d82ce8a4870e68b98653ea2d07b1ebd6a54586aca98d8d1ebdb684341368e8f9c3448adf5901e2f2
7
+ data.tar.gz: 8db2b3039051f23371d88c7f556f7ae39d12b75a39a7bd419b37630616d370a296daefb776fdbc59d73521158e2da1936e343079fd43a7286d25f47110d4006d
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 0.1.1
2
+
3
+ - Fix streaming upload.
4
+ - Fix delete by prefixed.
5
+ - Add full test.
6
+
7
+ ## 0.1.0
8
+
9
+ - First release.
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
- # ActivestorageAliyun
2
- Short description and motivation.
1
+ # ActiveStorage Aliyun Service
2
+
3
+ Wraps the Aliyun OSS as an Active Storage service.
4
+
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/activestorage-aliyun.svg)](https://badge.fury.io/rb/activestorage-aliyun) [![Build Status](https://travis-ci.org/huacnlee/activestorage-aliyun.svg)](https://travis-ci.org/huacnlee/activestorage-aliyun) [![Code Climate](https://codeclimate.com/github/huacnlee/activestorage-aliyun/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/activestorage-aliyun) [![codecov.io](https://codecov.io/github/huacnlee/activestorage-aliyun/coverage.svg?branch=master)](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
- Or install it yourself as:
20
- ```bash
21
- $ gem install activestorage-aliyun
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), file: io)
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
- bucket.get_object(path_for(key))
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.delete_object(path_for(prefix))
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 ||= client = Aliyun::OSS::Client.new(
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),
@@ -1,3 +1,3 @@
1
1
  module ActiveStorageAliyun
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,4 +1,4 @@
1
- require "active_storage_aliyun/railtie"
1
+ # require "active_storage_aliyun/railtie"
2
2
 
3
3
  module ActiveStorageAliyun
4
4
  # Your code goes here...
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.0
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