activestorage_qiniu 0.1.2 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +102 -0
- data/README.md +1 -1
- data/activestorage_qiniu.gemspec +1 -1
- data/lib/active_storage/service/qiniu_service.rb +40 -8
- data/lib/activestorage_qiniu.rb +1 -1
- data/lib/activestorage_qiniu/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47f6b2fc9d84e2d9259f30ee944d819d168de2718448b50b9b3f97439f5cb213
|
4
|
+
data.tar.gz: e490f65e548aa46088c1d41d452852b9ebd18edc5c2071950a907a275f7711d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f1228423a20a63ce8d103e46486e1cabd94a3e8adf1c3b60f9085f54839c0a6542ad8e5c949c1ddd8b9bf7b4433bda41cb2b3a6b7c8e21b1c484ec7899f1b5
|
7
|
+
data.tar.gz: 4fdbcc72749431be529838e398fc29eb6edae0ad0ea147699dcb792c11bd7ef2c714ead6df865bb5ac6deb61a1cf5b45d36e09f88b5823bb8b65736bbb2d9a50
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activestorage_qiniu (0.1.2)
|
5
|
+
activestorage (~> 0.1)
|
6
|
+
qiniu (~> 6.8.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (5.1.4)
|
12
|
+
actionview (= 5.1.4)
|
13
|
+
activesupport (= 5.1.4)
|
14
|
+
rack (~> 2.0)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
18
|
+
actionview (5.1.4)
|
19
|
+
activesupport (= 5.1.4)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
24
|
+
activejob (5.1.4)
|
25
|
+
activesupport (= 5.1.4)
|
26
|
+
globalid (>= 0.3.6)
|
27
|
+
activemodel (5.1.4)
|
28
|
+
activesupport (= 5.1.4)
|
29
|
+
activerecord (5.1.4)
|
30
|
+
activemodel (= 5.1.4)
|
31
|
+
activesupport (= 5.1.4)
|
32
|
+
arel (~> 8.0)
|
33
|
+
activestorage (0.1)
|
34
|
+
actionpack (>= 5.1)
|
35
|
+
activejob (>= 5.1)
|
36
|
+
activerecord (>= 5.1)
|
37
|
+
activesupport (>= 5.1)
|
38
|
+
activesupport (5.1.4)
|
39
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
40
|
+
i18n (~> 0.7)
|
41
|
+
minitest (~> 5.1)
|
42
|
+
tzinfo (~> 1.1)
|
43
|
+
arel (8.0.0)
|
44
|
+
builder (3.2.3)
|
45
|
+
concurrent-ruby (1.0.5)
|
46
|
+
crass (1.0.3)
|
47
|
+
domain_name (0.5.20170404)
|
48
|
+
unf (>= 0.0.5, < 1.0.0)
|
49
|
+
erubi (1.7.0)
|
50
|
+
globalid (0.4.1)
|
51
|
+
activesupport (>= 4.2.0)
|
52
|
+
http-cookie (1.0.3)
|
53
|
+
domain_name (~> 0.5)
|
54
|
+
i18n (0.9.1)
|
55
|
+
concurrent-ruby (~> 1.0)
|
56
|
+
json (1.8.6)
|
57
|
+
loofah (2.1.1)
|
58
|
+
crass (~> 1.0.2)
|
59
|
+
nokogiri (>= 1.5.9)
|
60
|
+
mime-types (2.99.3)
|
61
|
+
mini_portile2 (2.3.0)
|
62
|
+
minitest (5.10.3)
|
63
|
+
netrc (0.11.0)
|
64
|
+
nokogiri (1.8.1)
|
65
|
+
mini_portile2 (~> 2.3.0)
|
66
|
+
qiniu (6.8.1)
|
67
|
+
json (~> 1.8)
|
68
|
+
mime-types (~> 2.4, >= 2.4.0)
|
69
|
+
rest-client (~> 2.0, >= 2.0.0)
|
70
|
+
ruby-hmac (~> 0.4)
|
71
|
+
rack (2.0.3)
|
72
|
+
rack-test (0.8.2)
|
73
|
+
rack (>= 1.0, < 3)
|
74
|
+
rails-dom-testing (2.0.3)
|
75
|
+
activesupport (>= 4.2.0)
|
76
|
+
nokogiri (>= 1.6)
|
77
|
+
rails-html-sanitizer (1.0.3)
|
78
|
+
loofah (~> 2.0)
|
79
|
+
rake (10.5.0)
|
80
|
+
rest-client (2.0.2)
|
81
|
+
http-cookie (>= 1.0.2, < 2.0)
|
82
|
+
mime-types (>= 1.16, < 4.0)
|
83
|
+
netrc (~> 0.8)
|
84
|
+
ruby-hmac (0.4.0)
|
85
|
+
thread_safe (0.3.6)
|
86
|
+
tzinfo (1.2.4)
|
87
|
+
thread_safe (~> 0.1)
|
88
|
+
unf (0.1.4)
|
89
|
+
unf_ext
|
90
|
+
unf_ext (0.0.7.4)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
ruby
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
activestorage_qiniu!
|
97
|
+
bundler (~> 1.16)
|
98
|
+
minitest (~> 5.0)
|
99
|
+
rake (~> 10.0)
|
100
|
+
|
101
|
+
BUNDLED WITH
|
102
|
+
1.16.0
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Then, in your application's configuration, you can specify the service to use li
|
|
36
36
|
config.active_storage.service = :qiniu
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
Finally, config qiniu image and video analyzers.
|
40
40
|
|
41
41
|
```
|
42
42
|
config.active_storage.analyzers = [ ActiveStorage::Analyzer::QiniuImageAnalyzer, ActiveStorage::Analyzer::QiniuVideoAnalyzer ]
|
data/activestorage_qiniu.gemspec
CHANGED
@@ -21,13 +21,15 @@ module ActiveStorage
|
|
21
21
|
#
|
22
22
|
#
|
23
23
|
class Service::QiniuService < Service
|
24
|
-
attr_reader :bucket, :domain, :upload_options
|
24
|
+
attr_reader :bucket, :domain, :upload_options, :protocol
|
25
25
|
|
26
26
|
def initialize(access_key:, secret_key:, bucket:, domain:, **options)
|
27
27
|
@bucket = bucket
|
28
28
|
@domain = domain
|
29
|
+
@protocol = (options.delete(:protocol) || 'https').to_sym
|
29
30
|
Qiniu.establish_connection! access_key: access_key,
|
30
31
|
secret_key: secret_key,
|
32
|
+
protocol: protocol,
|
31
33
|
**options
|
32
34
|
|
33
35
|
@upload_options = options
|
@@ -36,15 +38,18 @@ module ActiveStorage
|
|
36
38
|
def upload(key, io, checksum: nil)
|
37
39
|
instrument :upload, key: key, checksum: checksum do
|
38
40
|
begin
|
39
|
-
|
41
|
+
upload_method = io.respond_to?(:read) ? :upload_buffer_with_token : :upload_with_token_2
|
42
|
+
code, result, response_headers = Qiniu::Storage.send(upload_method,
|
40
43
|
generate_uptoken(key),
|
41
44
|
io,
|
45
|
+
key,
|
42
46
|
nil,
|
43
47
|
bucket: bucket
|
44
48
|
)
|
45
49
|
|
46
50
|
result
|
47
|
-
rescue
|
51
|
+
rescue => e
|
52
|
+
puts e.backtrace
|
48
53
|
raise ActiveStorage::IntegrityError
|
49
54
|
end
|
50
55
|
end
|
@@ -70,14 +75,41 @@ module ActiveStorage
|
|
70
75
|
end
|
71
76
|
end
|
72
77
|
|
78
|
+
def download(key)
|
79
|
+
if block_given?
|
80
|
+
instrument :streaming_download, key: key do
|
81
|
+
open(url(key, disposition: :attachment)) do |file|
|
82
|
+
while data = file.read(64.kilobytes)
|
83
|
+
yield data
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
instrument :download, key: key do
|
89
|
+
open(url(key, disposition: :attachment)).read
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def download_chunk(key, range)
|
95
|
+
instrument :download_chunk, key: key, range: range do
|
96
|
+
uri = URI(url(key, disposition: :attachment))
|
97
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |client|
|
98
|
+
client.get(uri, 'Range' => "bytes=#{range.begin}-#{range.exclude_end? ? range.end - 1 : range.end}").body
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
73
103
|
def url(key, **options)
|
74
104
|
instrument :url, key: key do |payload|
|
75
105
|
fop = if options[:fop].present? # 内容预处理
|
76
106
|
options[:fop]
|
77
|
-
elsif options[:
|
78
|
-
|
107
|
+
elsif options[:disposition].to_s == 'attachment' # 下载附件
|
108
|
+
attname = URI.escape "#{options[:filename] || key}"
|
109
|
+
"attname=#{attname}"
|
79
110
|
end
|
80
|
-
|
111
|
+
expires_in = options[:expires_in] || url_expires_in
|
112
|
+
url = Qiniu::Auth.authorize_download_url_2(domain, key, fop: fop, expires_in: expires_in, schema: protocol)
|
81
113
|
payload[:url] = url
|
82
114
|
url
|
83
115
|
end
|
@@ -87,12 +119,12 @@ module ActiveStorage
|
|
87
119
|
instrument :url, key: key do |payload|
|
88
120
|
url = Qiniu::Config.up_host(bucket)
|
89
121
|
payload[:url] = url
|
90
|
-
|
122
|
+
url
|
91
123
|
end
|
92
124
|
end
|
93
125
|
|
94
126
|
def headers_for_direct_upload(key, content_type:, checksum:, **)
|
95
|
-
{ "Content-Type" => content_type, "Content-MD5" => checksum }
|
127
|
+
{ "Content-Type" => content_type, "Content-MD5" => checksum, "x-token" => generate_uptoken(key) }
|
96
128
|
end
|
97
129
|
|
98
130
|
private
|
data/lib/activestorage_qiniu.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.6
|
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:
|
12
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -77,16 +77,16 @@ dependencies:
|
|
77
77
|
name: qiniu
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 6.
|
82
|
+
version: 6.9.0
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 6.
|
89
|
+
version: 6.9.0
|
90
90
|
description: Wraps the Qiniu Storage Service as an Active Storage service. https://www.qiniu.com
|
91
91
|
email:
|
92
92
|
- sindon@gmail.com
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- ".travis.yml"
|
99
99
|
- CODE_OF_CONDUCT.md
|
100
100
|
- Gemfile
|
101
|
+
- Gemfile.lock
|
101
102
|
- LICENSE.txt
|
102
103
|
- README.md
|
103
104
|
- Rakefile
|
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
132
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.6
|
133
|
+
rubygems_version: 2.7.6
|
133
134
|
signing_key:
|
134
135
|
specification_version: 4
|
135
136
|
summary: Wraps the Qiniu Storage Service as an Active Storage service
|