carrierwave-aliyun 0.7.1 → 0.8.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
  SHA1:
3
- metadata.gz: f0f7b3f55576609ad049785f318c51e01b043527
4
- data.tar.gz: 3103ff2b3212f8f9d51f7aa1e74825f5c06d7f8a
3
+ metadata.gz: b4c3e25cff05a222bea176fd00d93bca1f0a1b8d
4
+ data.tar.gz: d3944b5799e7a265a412069638dac44299a4d5f5
5
5
  SHA512:
6
- metadata.gz: 6607d66d031946a8f035489e094cff75e380376eaf29e2e94d2e74d739df1ffe94ff237b7c1dfade9bd16f362235a687b67a6bf1a9a22af8bcb9f3db798511bb
7
- data.tar.gz: 42fee281007e4064fdd2fbf6202ac0222716d9cfccef8517be41cacd254b5e355a9c2e8686c8b2ff6d68af8263b633b6cc036b430efe666fbe6be8bfac37d92b
6
+ metadata.gz: d2e42fba4c36c234f5f7b95332993a1834fd82de3bde29694aa7a5b5a4043db9afa8341fff27b229b03eaeaa9ae6bdee9c338095ddc0505647a2521ba08a93ff
7
+ data.tar.gz: 5a9d5b8ff8433ced9b1ad46ae3be257a814880eee978399ca748daa91d15e43f279e88c0ba92b6b944a177fcb90b7adde3839caeb51f0e1a3a1639c8a45a365a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.8.1
2
+
3
+ - 去掉 `aliyun_img_host` 的配置项,不再需要了,Aliyun OSS 的 Bucket 域名以及默认执行图片处理协议,详见:[图片处理指南](https://help.aliyun.com/document_detail/44688.html).
4
+ - 在用户未设置 `aliyun_host` 的时候,默认返回 https 协议的 aliyun 主机地址。(#42)
5
+
1
6
  ## 0.7.1
2
7
 
3
8
  - Fix Storage's read. (#41)
data/README.md CHANGED
@@ -29,9 +29,7 @@ CarrierWave.configure do |config|
29
29
  # config.aliyun_area = "cn-hangzhou"
30
30
  # 使用自定义域名,设定此项,carrierwave 返回的 URL 将会用自定义域名
31
31
  # 自定于域名请 CNAME 到 you_bucket_name.oss-cn-hangzhou.aliyuncs.com (you_bucket_name 是你的 bucket 的名称)
32
- config.aliyun_host = "http://foo.bar.com"
33
- # 配置缩略图 Host,默认 #{aliyun_bucket}.img-#{aliyun_area}.aliyuncs.com
34
- # config.aliyun_img_host = "http://you_bucket_name.img-cn-hangzhou.aliyuncs.com"
32
+ config.aliyun_host = "https://foo.bar.com"
35
33
  # Bucket 为私有读取请设置 true,默认 false,以便得到的 URL 是能带有 private 空间访问权限的逻辑
36
34
  # config.aliyun_private_read = false
37
35
  end
@@ -39,21 +37,15 @@ end
39
37
 
40
38
  ## 阿里云 OSS 图片缩略图
41
39
 
42
- 从 **0.5.0** 版本开始,carrierwave-aliyun 支持 Aliyun OSS 的图片缩略图了,你只需要在 Uploader 对象的 `url` 函数后面跟上 `:thumb` 附带缩略图参数就可以了。
43
-
44
40
  > NOTE: 此方法同样支持 Private 的 Bucket 哦!
45
41
 
46
- 关于阿里云 OSS 图片缩略图的详细文档,请仔细阅读: [Aliyun OSS 接入图片服务](https://help.aliyun.com/document_detail/32210.html)
42
+ 关于阿里云 OSS 图片缩略图的详细文档,请仔细阅读: [Aliyun OSS 接入图片服务](https://help.aliyun.com/document_detail/44688.html)
47
43
 
48
44
  ```rb
49
- irb> User.last.avatar.url(thumb: '@100w_1c')
50
- https://simple.img-cn-hangzhou.aliyuncs.com/users/avatar/12.png@100w_1c
51
- irb> User.last.avatar.url(thumb: '@100w_200h_1c.jpg')
52
- https://simple.img-cn-hangzhou.aliyuncs.com/users/avatar/12.png@100w_200h_1c.jpg
53
- irb> User.last.avatar.url(thumb: '@100w_200h_1c_95q')
54
- https://simple.img-cn-hangzhou.aliyuncs.com/users/avatar/12.png@100w_200h_1c_95q
55
- # 你也可以用自定义的缩略图格式
56
- irb> User.last.avatar.url(thumb: '@!large')
45
+ irb> User.last.avatar.url(thumb: '?x-oss-process=image/resize,h_100')
46
+ "https://simple.oss-cn-hangzhou.aliyuncs.com/users/avatar/12.png?x-oss-process=image/resize,h_100"
47
+ irb> User.last.avatar.url(thumb: '?x-oss-process=image/resize,h_100,w_100')
48
+ "https://simple.oss-cn-hangzhou.aliyuncs.com/users/avatar/12.png?x-oss-process=image/resize,h_100,w_100"
57
49
  ```
58
50
 
59
51
  ## 增对文件设置 Content-Disposition
@@ -12,8 +12,7 @@ module CarrierWave
12
12
  @aliyun_internal = uploader.aliyun_internal
13
13
 
14
14
  # Host for get request
15
- @aliyun_host = uploader.aliyun_host || "http://#{@aliyun_bucket}.oss-#{@aliyun_area}.aliyuncs.com"
16
- @aliyun_img_host = uploader.aliyun_img_host || "http://#{@aliyun_bucket}.img-#{@aliyun_area}.aliyuncs.com"
15
+ @aliyun_host = uploader.aliyun_host || "https://#{@aliyun_bucket}.oss-#{@aliyun_area}.aliyuncs.com"
17
16
 
18
17
  unless @aliyun_host.include?('//')
19
18
  raise "config.aliyun_host requirement include // http:// or https://, but you give: #{@aliyun_host}"
@@ -84,7 +83,7 @@ module CarrierWave
84
83
  def path_to_url(path, opts = {})
85
84
  if opts[:thumb]
86
85
  thumb_path = [path, opts[:thumb]].join('')
87
- [@aliyun_img_host, thumb_path].join('/')
86
+ [@aliyun_host, thumb_path].join('/')
88
87
  else
89
88
  [@aliyun_host, path].join('/')
90
89
  end
@@ -94,12 +93,14 @@ module CarrierWave
94
93
  # 有效期 3600s
95
94
  def private_get_url(path, opts = {})
96
95
  path.sub!(PATH_PREFIX, '')
96
+ url = ''
97
97
  if opts[:thumb]
98
98
  thumb_path = [path, opts[:thumb]].join('')
99
- img_client.bucket_get_object_share_link(thumb_path, 3600)
99
+ url = img_client.bucket_get_object_share_link(thumb_path, 3600)
100
100
  else
101
- oss_client.bucket_get_object_share_link(path, 3600)
101
+ url = oss_client.bucket_get_object_share_link(path, 3600)
102
102
  end
103
+ url.gsub('http://', 'https://')
103
104
  end
104
105
 
105
106
  def head(path)
@@ -10,7 +10,6 @@ module CarrierWave
10
10
  add_config :aliyun_area
11
11
  add_config :aliyun_internal
12
12
  add_config :aliyun_host
13
- add_config :aliyun_img_host
14
13
  add_config :aliyun_private_read
15
14
 
16
15
  configure do |config|
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Aliyun
3
- VERSION = '0.7.1'
3
+ VERSION = '0.8.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -38,6 +38,76 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.1.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mini_magick
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
41
111
  description: Aliyun OSS support for Carrierwave
42
112
  email:
43
113
  - huacnlee@gmail.com
@@ -45,28 +115,14 @@ executables: []
45
115
  extensions: []
46
116
  extra_rdoc_files: []
47
117
  files:
48
- - ".gitignore"
49
- - ".rspec"
50
- - ".rubocop.yml"
51
- - ".travis.yml"
52
118
  - CHANGELOG.md
53
- - Gemfile
54
- - Gemfile.lock
55
119
  - README.md
56
- - Rakefile
57
- - carrierwave-aliyun.gemspec
58
120
  - lib/carrierwave-aliyun.rb
59
121
  - lib/carrierwave/aliyun/bucket.rb
60
122
  - lib/carrierwave/aliyun/configuration.rb
61
123
  - lib/carrierwave/aliyun/version.rb
62
124
  - lib/carrierwave/storage/aliyun.rb
63
125
  - lib/carrierwave/storage/aliyun_file.rb
64
- - spec/aliyun_spec.rb
65
- - spec/foo.gif
66
- - spec/foo.jpg
67
- - spec/foo.zip
68
- - spec/spec_helper.rb
69
- - spec/upload_spec.rb
70
126
  homepage: https://github.com/huacnlee/carrierwave-aliyun
71
127
  licenses:
72
128
  - MIT
@@ -91,10 +147,4 @@ rubygems_version: 2.5.2
91
147
  signing_key:
92
148
  specification_version: 4
93
149
  summary: Aliyun OSS support for Carrierwave
94
- test_files:
95
- - spec/aliyun_spec.rb
96
- - spec/foo.gif
97
- - spec/foo.jpg
98
- - spec/foo.zip
99
- - spec/spec_helper.rb
100
- - spec/upload_spec.rb
150
+ test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- .bundle/
2
- log/*.log
3
- pkg/
4
- test/dummy/db/*.sqlite3
5
- test/dummy/db/*.sqlite3-journal
6
- test/dummy/log/*.log
7
- test/dummy/tmp/
8
- coverage/
9
- uploads/
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour
data/.rubocop.yml DELETED
@@ -1,53 +0,0 @@
1
- Style/Documentation:
2
- Enabled: false
3
-
4
- Style/AsciiComments:
5
- Enabled: false
6
-
7
- Style/IfUnlessModifier:
8
- Enabled: false
9
-
10
- Style/RedundantSelf:
11
- Enabled: false
12
-
13
- Style/RaiseArgs:
14
- EnforcedStyle: compact
15
-
16
- Style/MutableConstant:
17
- Enabled: false
18
-
19
- Metrics/LineLength:
20
- Max: 1200
21
-
22
- Metrics/ClassLength:
23
- Max: 1200
24
-
25
- Metrics/MethodLength:
26
- Max: 1200
27
-
28
- Metrics/ModuleLength:
29
- Max: 1200
30
-
31
- Metrics/CyclomaticComplexity:
32
- Enabled: false
33
-
34
- Metrics/AbcSize:
35
- Enabled: false
36
-
37
- Metrics/PerceivedComplexity:
38
- Enabled: false
39
-
40
- Rails/TimeZone:
41
- Enabled: false
42
-
43
- Style/GlobalVars:
44
- Enabled: false
45
-
46
- Style/GuardClause:
47
- Enabled: false
48
-
49
- Rails/FindBy:
50
- Enabled: false
51
-
52
- Rails/HasAndBelongsToMany:
53
- Enabled: false
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- bundler_args: --without development
3
-
4
- rvm:
5
- - 2.3.0
6
-
7
- script: rspec spec
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake'
6
- gem 'rails', '~> 4.2.0'
7
- gem 'sqlite3-ruby', require: 'sqlite3'
8
- gem 'mini_magick'
9
- gem 'rspec'
data/Gemfile.lock DELETED
@@ -1,153 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- carrierwave-aliyun (0.7.1)
5
- aliyun-oss-sdk (>= 0.1.6)
6
- carrierwave (>= 0.5.7)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionmailer (4.2.6)
12
- actionpack (= 4.2.6)
13
- actionview (= 4.2.6)
14
- activejob (= 4.2.6)
15
- mail (~> 2.5, >= 2.5.4)
16
- rails-dom-testing (~> 1.0, >= 1.0.5)
17
- actionpack (4.2.6)
18
- actionview (= 4.2.6)
19
- activesupport (= 4.2.6)
20
- rack (~> 1.6)
21
- rack-test (~> 0.6.2)
22
- rails-dom-testing (~> 1.0, >= 1.0.5)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- actionview (4.2.6)
25
- activesupport (= 4.2.6)
26
- builder (~> 3.1)
27
- erubis (~> 2.7.0)
28
- rails-dom-testing (~> 1.0, >= 1.0.5)
29
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- activejob (4.2.6)
31
- activesupport (= 4.2.6)
32
- globalid (>= 0.3.0)
33
- activemodel (4.2.6)
34
- activesupport (= 4.2.6)
35
- builder (~> 3.1)
36
- activerecord (4.2.6)
37
- activemodel (= 4.2.6)
38
- activesupport (= 4.2.6)
39
- arel (~> 6.0)
40
- activesupport (4.2.6)
41
- i18n (~> 0.7)
42
- json (~> 1.7, >= 1.7.7)
43
- minitest (~> 5.1)
44
- thread_safe (~> 0.3, >= 0.3.4)
45
- tzinfo (~> 1.1)
46
- addressable (2.5.0)
47
- public_suffix (~> 2.0, >= 2.0.2)
48
- aliyun-oss-sdk (0.1.8)
49
- addressable
50
- gyoku
51
- httparty
52
- arel (6.0.3)
53
- builder (3.2.2)
54
- carrierwave (1.0.0)
55
- activemodel (>= 4.0.0)
56
- activesupport (>= 4.0.0)
57
- mime-types (>= 1.16)
58
- concurrent-ruby (1.0.2)
59
- diff-lcs (1.2.5)
60
- erubis (2.7.0)
61
- globalid (0.3.6)
62
- activesupport (>= 4.1.0)
63
- gyoku (1.3.1)
64
- builder (>= 2.1.2)
65
- httparty (0.14.0)
66
- multi_xml (>= 0.5.2)
67
- i18n (0.7.0)
68
- json (1.8.3)
69
- loofah (2.0.3)
70
- nokogiri (>= 1.5.9)
71
- mail (2.6.4)
72
- mime-types (>= 1.16, < 4)
73
- mime-types (3.1)
74
- mime-types-data (~> 3.2015)
75
- mime-types-data (3.2016.0521)
76
- mini_magick (4.4.0)
77
- mini_portile2 (2.1.0)
78
- minitest (5.9.0)
79
- multi_xml (0.6.0)
80
- nokogiri (1.6.8)
81
- mini_portile2 (~> 2.1.0)
82
- pkg-config (~> 1.1.7)
83
- pkg-config (1.1.7)
84
- public_suffix (2.0.4)
85
- rack (1.6.4)
86
- rack-test (0.6.3)
87
- rack (>= 1.0)
88
- rails (4.2.6)
89
- actionmailer (= 4.2.6)
90
- actionpack (= 4.2.6)
91
- actionview (= 4.2.6)
92
- activejob (= 4.2.6)
93
- activemodel (= 4.2.6)
94
- activerecord (= 4.2.6)
95
- activesupport (= 4.2.6)
96
- bundler (>= 1.3.0, < 2.0)
97
- railties (= 4.2.6)
98
- sprockets-rails
99
- rails-deprecated_sanitizer (1.0.3)
100
- activesupport (>= 4.2.0.alpha)
101
- rails-dom-testing (1.0.7)
102
- activesupport (>= 4.2.0.beta, < 5.0)
103
- nokogiri (~> 1.6.0)
104
- rails-deprecated_sanitizer (>= 1.0.1)
105
- rails-html-sanitizer (1.0.3)
106
- loofah (~> 2.0)
107
- railties (4.2.6)
108
- actionpack (= 4.2.6)
109
- activesupport (= 4.2.6)
110
- rake (>= 0.8.7)
111
- thor (>= 0.18.1, < 2.0)
112
- rake (11.2.2)
113
- rspec (3.4.0)
114
- rspec-core (~> 3.4.0)
115
- rspec-expectations (~> 3.4.0)
116
- rspec-mocks (~> 3.4.0)
117
- rspec-core (3.4.3)
118
- rspec-support (~> 3.4.0)
119
- rspec-expectations (3.4.0)
120
- diff-lcs (>= 1.2.0, < 2.0)
121
- rspec-support (~> 3.4.0)
122
- rspec-mocks (3.4.1)
123
- diff-lcs (>= 1.2.0, < 2.0)
124
- rspec-support (~> 3.4.0)
125
- rspec-support (3.4.1)
126
- sprockets (3.6.2)
127
- concurrent-ruby (~> 1.0)
128
- rack (> 1, < 3)
129
- sprockets-rails (3.1.1)
130
- actionpack (>= 4.0)
131
- activesupport (>= 4.0)
132
- sprockets (>= 3.0.0)
133
- sqlite3 (1.3.11)
134
- sqlite3-ruby (1.3.3)
135
- sqlite3 (>= 1.3.3)
136
- thor (0.19.1)
137
- thread_safe (0.3.5)
138
- tzinfo (1.2.2)
139
- thread_safe (~> 0.1)
140
-
141
- PLATFORMS
142
- ruby
143
-
144
- DEPENDENCIES
145
- carrierwave-aliyun!
146
- mini_magick
147
- rails (~> 4.2.0)
148
- rake
149
- rspec
150
- sqlite3-ruby
151
-
152
- BUNDLED WITH
153
- 1.13.6
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- Bundler::GemHelper.install_tasks
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
- require File.expand_path('lib/carrierwave/aliyun/version')
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'carrierwave-aliyun'
7
- s.version = CarrierWave::Aliyun::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Jason Lee']
10
- s.email = ['huacnlee@gmail.com']
11
- s.homepage = 'https://github.com/huacnlee/carrierwave-aliyun'
12
- s.summary = 'Aliyun OSS support for Carrierwave'
13
- s.description = 'Aliyun OSS support for Carrierwave'
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
- s.require_paths = ['lib']
18
- s.license = 'MIT'
19
-
20
- s.add_dependency 'carrierwave', ['>= 0.5.7']
21
- s.add_dependency 'aliyun-oss-sdk', ['>= 0.1.6']
22
- end
data/spec/aliyun_spec.rb DELETED
@@ -1,83 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'Aliyun' do
4
- before(:all) do
5
- @opts = {
6
- aliyun_access_id: ALIYUN_ACCESS_ID,
7
- aliyun_access_key: ALIYUN_ACCESS_KEY,
8
- aliyun_bucket: ALIYUN_BUCKET,
9
- aliyun_area: ALIYUN_AREA,
10
- aliyun_internal: false,
11
- aliyun_host: 'http://test.cn-hangzhou.oss.aliyun-inc.com'
12
- }
13
-
14
- @uploader = CarrierWave::Uploader::Base.new
15
- @bucket = CarrierWave::Aliyun::Bucket.new(@uploader)
16
- end
17
-
18
- # it "should put by internal network" do
19
- # @uploader.aliyun_internal = true
20
- # @connection = CarrierWave::Storage::Aliyun.new(@uploader)
21
- # puts @connection.to_json
22
- # url = @connection.put("/a/a.jpg",load_file("foo.jpg"))
23
- # res = Net::HTTP.get_response(URI.parse(url))
24
- # puts res.to_json
25
- # expect(res.code).to eq "200"
26
- # end
27
-
28
- it 'should put' do
29
- url = @bucket.put('a/a.jpg', load_file('foo.jpg'))
30
- res = Net::HTTP.get_response(URI.parse(url))
31
- expect(res.code).to eq '200'
32
- end
33
-
34
- it 'should put with / prefix' do
35
- url = @bucket.put('/a/a.jpg', load_file('foo.jpg'))
36
- res = Net::HTTP.get_response(URI.parse(url))
37
- expect(res.code).to eq '200'
38
- end
39
-
40
- it 'should delete' do
41
- url = @bucket.delete('/a/a.jpg')
42
- res = Net::HTTP.get_response(URI.parse(url))
43
- expect(res.code).to eq '404'
44
- end
45
-
46
- it 'should support custom domain' do
47
- @uploader.aliyun_host = 'https://foo.bar.com'
48
- @bucket = CarrierWave::Aliyun::Bucket.new(@uploader)
49
- url = @bucket.put('a/a.jpg', load_file('foo.jpg'))
50
- expect(url).to eq 'https://foo.bar.com/a/a.jpg'
51
- @uploader.aliyun_host = 'http://foo.bar.com'
52
- @bucket = CarrierWave::Aliyun::Bucket.new(@uploader)
53
- url = @bucket.put('a/a.jpg', load_file('foo.jpg'))
54
- expect(url).to eq 'http://foo.bar.com/a/a.jpg'
55
- end
56
-
57
- describe 'private read bucket' do
58
- before do
59
- @uploader.aliyun_private_read = true
60
- @bucket = CarrierWave::Aliyun::Bucket.new(@uploader)
61
- end
62
-
63
- it 'should get url include token' do
64
- url = @bucket.private_get_url('bar/foo.jpg')
65
- # http://oss-cn-beijing.aliyuncs.com.//carrierwave-aliyun-test.oss-cn-beijing.aliyuncs.com/bar/foo.jpg?OSSAccessKeyId=1OpWEtPTjIDv5u8q&Expires=1455172009&Signature=4ibgQpfHOjVpqxG6162S8Ar3c6c=
66
- expect(url).to include(*%w(Signature Expires OSSAccessKeyId))
67
- expect(url).to include "http://#{@uploader.aliyun_bucket}.oss-#{@uploader.aliyun_area}.aliyuncs.com/bar/foo.jpg"
68
- end
69
-
70
- it 'should get url with :thumb' do
71
- url = @bucket.private_get_url('bar/foo.jpg', thumb: '@100w_200h_90q')
72
- expect(url).to include "http://#{@uploader.aliyun_bucket}.img-cn-beijing.aliyuncs.com/bar/foo.jpg@100w_200h_90q"
73
- end
74
- end
75
-
76
- describe 'File' do
77
- it 'should have respond_to identifier' do
78
- f = CarrierWave::Storage::AliyunFile.new(@uploader, '', '')
79
- expect(f).to respond_to(:identifier)
80
- expect(f).to respond_to(:filename)
81
- end
82
- end
83
- end
data/spec/foo.gif DELETED
Binary file
data/spec/foo.jpg DELETED
Binary file
data/spec/foo.zip DELETED
Binary file
data/spec/spec_helper.rb DELETED
@@ -1,45 +0,0 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- require 'rails'
4
- require 'active_record'
5
- require 'carrierwave'
6
- require 'carrierwave/orm/activerecord'
7
- require 'carrierwave/processing/mini_magick'
8
- require 'open-uri'
9
- require 'net/http'
10
-
11
- $LOAD_PATH.unshift(File.dirname(__FILE__))
12
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
-
14
- require 'carrierwave-aliyun'
15
-
16
- module Rails
17
- class <<self
18
- def root
19
- [File.expand_path(__FILE__).split('/')[0..-3].join('/'), 'spec'].join('/')
20
- end
21
- end
22
- end
23
-
24
- ActiveRecord::Migration.verbose = false
25
- ActiveRecord::Base.raise_in_transactional_callbacks = true
26
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
27
- database: ':memory:')
28
-
29
- ALIYUN_ACCESS_ID = ENV['ALIYUN_ACCESS_ID'] || ''
30
- ALIYUN_ACCESS_KEY = ENV['ALIYUN_ACCESS_KEY'] || ''
31
- ALIYUN_BUCKET = ENV['ALIYUN_BUCKET'] || 'carrierwave-aliyun-test'
32
- ALIYUN_AREA = ENV['ALIYUN_AREA'] || 'cn-beijing'
33
-
34
- CarrierWave.configure do |config|
35
- config.storage = :aliyun
36
- config.aliyun_access_id = ALIYUN_ACCESS_ID
37
- config.aliyun_access_key = ALIYUN_ACCESS_KEY
38
- config.aliyun_bucket = ALIYUN_BUCKET
39
- config.aliyun_area = ALIYUN_AREA
40
- config.aliyun_internal = false
41
- end
42
-
43
- def load_file(fname)
44
- File.open([Rails.root, fname].join('/'))
45
- end
data/spec/upload_spec.rb DELETED
@@ -1,135 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'Upload' do
4
- def setup_db
5
- ActiveRecord::Schema.define(version: 1) do
6
- create_table :photos do |t|
7
- t.column :image, :string
8
- t.column :content_type, :string
9
- end
10
-
11
- create_table :attachments do |t|
12
- t.column :file, :string
13
- t.column :content_type, :string
14
- end
15
- end
16
- end
17
-
18
- def drop_db
19
- ActiveRecord::Base.connection.tables.each do |table|
20
- ActiveRecord::Base.connection.drop_table(table)
21
- end
22
- end
23
-
24
- class PhotoUploader < CarrierWave::Uploader::Base
25
- include CarrierWave::MiniMagick
26
-
27
- version :small do
28
- process resize_to_fill: [120, 120]
29
- end
30
-
31
- def store_dir
32
- 'photos'
33
- end
34
- end
35
-
36
- class AttachUploader < CarrierWave::Uploader::Base
37
- include CarrierWave::MiniMagick
38
-
39
- def store_dir
40
- 'attachs'
41
- end
42
-
43
- def content_disposition
44
- "attachment;filename=#{file.original_filename}"
45
- end
46
- end
47
-
48
- class Photo < ActiveRecord::Base
49
- mount_uploader :image, PhotoUploader
50
- end
51
-
52
- class Attachment < ActiveRecord::Base
53
- mount_uploader :file, AttachUploader
54
- end
55
-
56
- before :all do
57
- setup_db
58
- end
59
-
60
- after :all do
61
- drop_db
62
- end
63
-
64
- describe 'Upload Image' do
65
- context 'should upload image' do
66
- before(:all) do
67
- @file = load_file('foo.jpg')
68
- @file1 = load_file('foo.gif')
69
- @photo = Photo.new(image: @file)
70
- @photo1 = Photo.new(image: @file1)
71
- end
72
-
73
- it 'should upload file' do
74
- expect(@photo.save).to eq true
75
- expect(@photo[:image].present?).to eq true
76
- # FIXME: image? 需要实现
77
- # expect(@photo.image?).to eq true
78
- end
79
-
80
- it 'should get uploaded file' do
81
- img = open(@photo.image.url)
82
- expect(img.size).to eq @file.size
83
- expect(img.content_type).to eq 'image/jpeg'
84
-
85
- expect(@photo1.save).to eq true
86
- img1 = open(@photo1.image.url)
87
- expect(img1.size).to eq @file1.size
88
- expect(img1.content_type).to eq 'image/gif'
89
- end
90
-
91
- it 'sholud get small version uploaded file' do
92
- expect(open(@photo.image.small.url)).not_to eq nil
93
- expect(open(@photo1.image.small.url)).not_to eq nil
94
- end
95
-
96
- it 'should get Aliyun OSS thumb url with :thumb option' do
97
- url = @photo.image.url(thumb: '@150w_140h.png')
98
- expect(url).to include('.img-')
99
- expect(url).to include('@150w_140h.png')
100
- url1 = @photo.image.url(thumb: '@!150w_140h.jpg')
101
- expect(url1).to include('.img-')
102
- expect(url1).to include('@!150w_140h.jpg')
103
- img1 = open(url)
104
- expect(img1.size).not_to eq 0
105
- expect(img1.content_type).to eq 'image/png'
106
- end
107
- end
108
-
109
- context 'should update zip' do
110
- before(:all) do
111
- @file = load_file('foo.zip')
112
- @attachment = Attachment.new(file: @file)
113
- end
114
-
115
- it 'should upload file' do
116
- expect(@attachment.save).to eq true
117
- end
118
-
119
- it 'should get uploaded file' do
120
- attach = open(@attachment.file.url)
121
- expect(attach.size).to eq @file.size
122
- expect(attach.content_type).to eq 'application/zip'
123
- expect(attach.meta['content-disposition']).to eq 'attachment;filename=foo.zip'
124
- end
125
-
126
- it 'should delete old file when upload a new file again' do
127
- old_url = @attachment.file.url
128
- @attachment.file = load_file('foo.gif')
129
- @attachment.save
130
- res = Net::HTTP.get_response(URI.parse(old_url))
131
- expect(res.code).to eq '404'
132
- end
133
- end
134
- end
135
- end