activestorage_qiniu 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66dd8ccc4e92df60e083a59af68e0d9c6af449f30905fcd5d0bfbcad646a9376
4
- data.tar.gz: 5c1b62fe52270d329f007b17a0fa0821be07995e2faacba6cf78aa400b1ca22b
3
+ metadata.gz: 3d7979a0cacc3f25e0705c90336bc7deb291a8ae4c0dbda880eb2d9f89c093a9
4
+ data.tar.gz: 92b947b4ffb4f8be7a20b1a14f5f107d11a07333d33128fb9cee01c67846504a
5
5
  SHA512:
6
- metadata.gz: f7fabebadd0ba37fe9e8334dd78637df4a030464f0d77433e16a7a2710a45f1cd8cc7ac8553ca0071b6eedabf79dcb577fb8e5ae3b8a1e9ffe12fd23f4438303
7
- data.tar.gz: a879fe519784c504edd5c8fe5f358967f79a563951161a3479c56d841a8e86274120853180d1ee9a8548002fc6bc2e7feb262fe07b6af195b121cf081b64c04f
6
+ metadata.gz: 850ce44e653999bf54bf8f0a7c44f538889f5622fe49cfb451639446e122cf6bb407b284cf743f2fae197f37d31a0e7b59d990630f09feeb2aa3153dcf820088
7
+ data.tar.gz: 7d517f6d54790257293bab7e660cccd2207a60b086d94a1ec4ae5a9d1aad9defa53ad3a3ed17751e15f59e5344e93eff003f6adff7abf8c359d7c4007ae94ad9
data/Gemfile.lock CHANGED
@@ -4,65 +4,80 @@ PATH
4
4
  activestorage_qiniu (0.2.0)
5
5
  qiniu (~> 6.9)
6
6
  rails (>= 5.1.6.2)
7
+ retries (~> 0.0.5)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- actioncable (5.2.2.1)
12
- actionpack (= 5.2.2.1)
12
+ actioncable (6.0.0)
13
+ actionpack (= 6.0.0)
13
14
  nio4r (~> 2.0)
14
15
  websocket-driver (>= 0.6.1)
15
- actionmailer (5.2.2.1)
16
- actionpack (= 5.2.2.1)
17
- actionview (= 5.2.2.1)
18
- activejob (= 5.2.2.1)
16
+ actionmailbox (6.0.0)
17
+ actionpack (= 6.0.0)
18
+ activejob (= 6.0.0)
19
+ activerecord (= 6.0.0)
20
+ activestorage (= 6.0.0)
21
+ activesupport (= 6.0.0)
22
+ mail (>= 2.7.1)
23
+ actionmailer (6.0.0)
24
+ actionpack (= 6.0.0)
25
+ actionview (= 6.0.0)
26
+ activejob (= 6.0.0)
19
27
  mail (~> 2.5, >= 2.5.4)
20
28
  rails-dom-testing (~> 2.0)
21
- actionpack (5.2.2.1)
22
- actionview (= 5.2.2.1)
23
- activesupport (= 5.2.2.1)
29
+ actionpack (6.0.0)
30
+ actionview (= 6.0.0)
31
+ activesupport (= 6.0.0)
24
32
  rack (~> 2.0)
25
33
  rack-test (>= 0.6.3)
26
34
  rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.2.2.1)
29
- activesupport (= 5.2.2.1)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.0.0)
37
+ actionpack (= 6.0.0)
38
+ activerecord (= 6.0.0)
39
+ activestorage (= 6.0.0)
40
+ activesupport (= 6.0.0)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.0.0)
43
+ activesupport (= 6.0.0)
30
44
  builder (~> 3.1)
31
45
  erubi (~> 1.4)
32
46
  rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activejob (5.2.2.1)
35
- activesupport (= 5.2.2.1)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.0.0)
49
+ activesupport (= 6.0.0)
36
50
  globalid (>= 0.3.6)
37
- activemodel (5.2.2.1)
38
- activesupport (= 5.2.2.1)
39
- activerecord (5.2.2.1)
40
- activemodel (= 5.2.2.1)
41
- activesupport (= 5.2.2.1)
42
- arel (>= 9.0)
43
- activestorage (5.2.2.1)
44
- actionpack (= 5.2.2.1)
45
- activerecord (= 5.2.2.1)
51
+ activemodel (6.0.0)
52
+ activesupport (= 6.0.0)
53
+ activerecord (6.0.0)
54
+ activemodel (= 6.0.0)
55
+ activesupport (= 6.0.0)
56
+ activestorage (6.0.0)
57
+ actionpack (= 6.0.0)
58
+ activejob (= 6.0.0)
59
+ activerecord (= 6.0.0)
46
60
  marcel (~> 0.3.1)
47
- activesupport (5.2.2.1)
61
+ activesupport (6.0.0)
48
62
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
63
  i18n (>= 0.7, < 2)
50
64
  minitest (~> 5.1)
51
65
  tzinfo (~> 1.1)
52
- arel (9.0.0)
66
+ zeitwerk (~> 2.1, >= 2.1.8)
53
67
  builder (3.2.3)
54
68
  concurrent-ruby (1.1.5)
55
- crass (1.0.4)
56
- domain_name (0.5.20180417)
69
+ crass (1.0.5)
70
+ domain_name (0.5.20190701)
57
71
  unf (>= 0.0.5, < 1.0.0)
58
- erubi (1.8.0)
72
+ erubi (1.9.0)
59
73
  globalid (0.4.2)
60
74
  activesupport (>= 4.2.0)
75
+ http-accept (1.7.0)
61
76
  http-cookie (1.0.3)
62
77
  domain_name (~> 0.5)
63
- i18n (1.6.0)
78
+ i18n (1.7.0)
64
79
  concurrent-ruby (~> 1.0)
65
- loofah (2.2.3)
80
+ loofah (2.3.1)
66
81
  crass (~> 1.0.2)
67
82
  nokogiri (>= 1.5.9)
68
83
  mail (2.7.1)
@@ -70,53 +85,57 @@ GEM
70
85
  marcel (0.3.3)
71
86
  mimemagic (~> 0.3.2)
72
87
  method_source (0.9.2)
73
- mime-types (3.2.2)
88
+ mime-types (3.3)
74
89
  mime-types-data (~> 3.2015)
75
- mime-types-data (3.2018.0812)
90
+ mime-types-data (3.2019.1009)
76
91
  mimemagic (0.3.3)
77
- mini_mime (1.0.1)
92
+ mini_mime (1.0.2)
78
93
  mini_portile2 (2.4.0)
79
94
  minitest (5.11.3)
80
95
  netrc (0.11.0)
81
- nio4r (2.3.1)
82
- nokogiri (1.10.1)
96
+ nio4r (2.5.2)
97
+ nokogiri (1.10.5)
83
98
  mini_portile2 (~> 2.4.0)
84
99
  qiniu (6.9.0)
85
100
  mime-types (~> 3.1)
86
101
  rest-client (~> 2.0)
87
- rack (2.0.6)
102
+ rack (2.0.7)
88
103
  rack-test (1.1.0)
89
104
  rack (>= 1.0, < 3)
90
- rails (5.2.2.1)
91
- actioncable (= 5.2.2.1)
92
- actionmailer (= 5.2.2.1)
93
- actionpack (= 5.2.2.1)
94
- actionview (= 5.2.2.1)
95
- activejob (= 5.2.2.1)
96
- activemodel (= 5.2.2.1)
97
- activerecord (= 5.2.2.1)
98
- activestorage (= 5.2.2.1)
99
- activesupport (= 5.2.2.1)
105
+ rails (6.0.0)
106
+ actioncable (= 6.0.0)
107
+ actionmailbox (= 6.0.0)
108
+ actionmailer (= 6.0.0)
109
+ actionpack (= 6.0.0)
110
+ actiontext (= 6.0.0)
111
+ actionview (= 6.0.0)
112
+ activejob (= 6.0.0)
113
+ activemodel (= 6.0.0)
114
+ activerecord (= 6.0.0)
115
+ activestorage (= 6.0.0)
116
+ activesupport (= 6.0.0)
100
117
  bundler (>= 1.3.0)
101
- railties (= 5.2.2.1)
118
+ railties (= 6.0.0)
102
119
  sprockets-rails (>= 2.0.0)
103
120
  rails-dom-testing (2.0.3)
104
121
  activesupport (>= 4.2.0)
105
122
  nokogiri (>= 1.6)
106
- rails-html-sanitizer (1.0.4)
107
- loofah (~> 2.2, >= 2.2.2)
108
- railties (5.2.2.1)
109
- actionpack (= 5.2.2.1)
110
- activesupport (= 5.2.2.1)
123
+ rails-html-sanitizer (1.3.0)
124
+ loofah (~> 2.3)
125
+ railties (6.0.0)
126
+ actionpack (= 6.0.0)
127
+ activesupport (= 6.0.0)
111
128
  method_source
112
129
  rake (>= 0.8.7)
113
- thor (>= 0.19.0, < 2.0)
130
+ thor (>= 0.20.3, < 2.0)
114
131
  rake (10.5.0)
115
- rest-client (2.0.2)
132
+ rest-client (2.1.0)
133
+ http-accept (>= 1.7.0, < 2.0)
116
134
  http-cookie (>= 1.0.2, < 2.0)
117
135
  mime-types (>= 1.16, < 4.0)
118
136
  netrc (~> 0.8)
119
- sprockets (3.7.2)
137
+ retries (0.0.5)
138
+ sprockets (4.0.0)
120
139
  concurrent-ruby (~> 1.0)
121
140
  rack (> 1, < 3)
122
141
  sprockets-rails (3.2.1)
@@ -129,10 +148,11 @@ GEM
129
148
  thread_safe (~> 0.1)
130
149
  unf (0.1.4)
131
150
  unf_ext
132
- unf_ext (0.0.7.5)
133
- websocket-driver (0.7.0)
151
+ unf_ext (0.0.7.6)
152
+ websocket-driver (0.7.1)
134
153
  websocket-extensions (>= 0.1.0)
135
- websocket-extensions (0.1.3)
154
+ websocket-extensions (0.1.4)
155
+ zeitwerk (2.2.1)
136
156
 
137
157
  PLATFORMS
138
158
  ruby
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.16"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
- spec.add_runtime_dependency 'rails', '~> 5.1', '>= 5.1.6.2'
26
+ spec.add_runtime_dependency 'rails', '>= 5.1.6.2'
27
27
 
28
28
  spec.add_dependency 'qiniu', '~> 6.9'
29
+ spec.add_dependency 'retries', '~> 0.0.5'
29
30
  end
@@ -1,4 +1,5 @@
1
1
  require 'open-uri'
2
+ require 'retries'
2
3
 
3
4
  module ActiveStorage
4
5
  # Wraps the Qiniu Storage Service as an Active Storage service.
@@ -24,6 +25,7 @@ module ActiveStorage
24
25
  #
25
26
  #
26
27
  class Service::QiniuService < Service
28
+ BLOCK_SIZE = 4 * 1024 * 1024
27
29
  attr_reader :bucket, :domain, :upload_options, :protocol, :bucket_private
28
30
 
29
31
  def initialize(access_key:, secret_key:, bucket:, domain:, **options)
@@ -42,21 +44,27 @@ module ActiveStorage
42
44
 
43
45
  def upload(key, io, checksum: nil, content_type: nil, **)
44
46
  instrument :upload, key: key, checksum: checksum do
45
- begin
46
- upload_method = io.respond_to?(:read) ? :upload_buffer_with_token : :upload_with_token_2
47
- code, result, response_headers = Qiniu::Storage.send(upload_method,
48
- generate_uptoken(key),
49
- io,
50
- key,
51
- nil,
52
- bucket: bucket
53
- )
54
-
55
- result
56
- rescue => e
57
- puts e.backtrace
58
- raise ActiveStorage::IntegrityError
47
+ io = File.open(io) unless io.respond_to?(:read)
48
+
49
+ ctx_list = []
50
+ file_size = 0
51
+ while (blk = io.read(BLOCK_SIZE))
52
+ ctx = upload_blk(key, blk)
53
+ file_size += blk.size
54
+ ctx_list.push(ctx)
59
55
  end
56
+
57
+ api_call(
58
+ key,
59
+ '/' + [
60
+ 'mkfile',
61
+ file_size,
62
+ 'key',
63
+ encode(key),
64
+ *(content_type ? ['mimeType', encode(content_type)] : [])
65
+ ].join('/'),
66
+ ctx_list.join(',')
67
+ )
60
68
  end
61
69
  end
62
70
 
@@ -119,7 +127,7 @@ module ActiveStorage
119
127
  Qiniu::Auth.authorize_download_url_2(domain, key, schema: protocol, fop: fop, expires_in: expires_in)
120
128
  else
121
129
  url_encoded_key = CGI::escape(key)
122
- "#{protocol}://#{domain}/#{url_encoded_key}"
130
+ "#{protocol}://#{domain}/#{url_encoded_key}?#{fop}"
123
131
  end
124
132
 
125
133
  payload[:url] = url
@@ -161,5 +169,31 @@ module ActiveStorage
161
169
 
162
170
  Qiniu::Auth.generate_uptoken(put_policy)
163
171
  end
172
+
173
+ def upload_blk(key, blk)
174
+ result =
175
+ with_retries(max_retries: 3) do
176
+ api_call(key, "/mkblk/#{blk.size}", blk)
177
+ end
178
+ result.fetch('ctx')
179
+ end
180
+
181
+ def api_call(key, path, body)
182
+ url = Qiniu::Config.up_host(bucket) + path
183
+
184
+ response = RestClient.post(
185
+ url,
186
+ body,
187
+ 'Authorization' => "UpToken #{generate_uptoken(key)}"
188
+ )
189
+
190
+ result = JSON.parse(response.body)
191
+
192
+ result
193
+ end
194
+
195
+ def encode(value)
196
+ Base64.encode64(value).strip.gsub(/\+/, '-').gsub(%r{/}, '_')
197
+ end
164
198
  end
165
- end
199
+ end
@@ -1,3 +1,3 @@
1
1
  module ActivestorageQiniu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage_qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mycolorway
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-03-20 00:00:00.000000000 Z
12
+ date: 2020-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -57,9 +57,6 @@ dependencies:
57
57
  name: rails
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '5.1'
63
60
  - - ">="
64
61
  - !ruby/object:Gem::Version
65
62
  version: 5.1.6.2
@@ -67,9 +64,6 @@ dependencies:
67
64
  prerelease: false
68
65
  version_requirements: !ruby/object:Gem::Requirement
69
66
  requirements:
70
- - - "~>"
71
- - !ruby/object:Gem::Version
72
- version: '5.1'
73
67
  - - ">="
74
68
  - !ruby/object:Gem::Version
75
69
  version: 5.1.6.2
@@ -87,6 +81,20 @@ dependencies:
87
81
  - - "~>"
88
82
  - !ruby/object:Gem::Version
89
83
  version: '6.9'
84
+ - !ruby/object:Gem::Dependency
85
+ name: retries
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.0.5
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.0.5
90
98
  description: Wraps the Qiniu Storage Service as an Active Storage service. https://www.qiniu.com
91
99
  email:
92
100
  - sindon@gmail.com
@@ -129,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
137
  - !ruby/object:Gem::Version
130
138
  version: '0'
131
139
  requirements: []
132
- rubygems_version: 3.0.3
140
+ rubygems_version: 3.1.2
133
141
  signing_key:
134
142
  specification_version: 4
135
143
  summary: Wraps the Qiniu Storage Service as an Active Storage service