paperclip-storage-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/Gemfile +1 -1
- data/README.md +16 -0
- data/lib/aliyun/connection.rb +4 -4
- data/paperclip-storage-aliyun.gemspec +1 -1
- data/spec/aliyun_spec.rb +18 -0
- data/spec/attachments//347/276/216/345/245/263.jpg +0 -0
- data/spec/lib/paperclip/storage/aliyun_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc88eeef9e399e74817562b2fbb525257e0240cf
|
4
|
+
data.tar.gz: 680b18f58b81bace15aa4e63e59fe7d862e6128d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 540eb2053d03facff5b05791eaee3e829296bd1cd6f149326598369530c425307ac5d2fa407dd13ab5479855b8063d1b38268a9fc53a3de912e9e7c52ea4fa44
|
7
|
+
data.tar.gz: 24098248c2e5786d0e091c10bd9e5f7eecd70cb930a789fcfa1ebc0b2334388ee71236d2927f07f085dd871bc7a66fb97663d1565bb4e42bae28c7e7703318ef
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -45,3 +45,19 @@ Similar to Paperclip::Storage::S3, there are four options for the url by now:
|
|
45
45
|
- `:aliyun_alias_url` : the alias url based on the `host_alias` you give, typically used together with CDN
|
46
46
|
|
47
47
|
Please note the values above are all strings, not symbols. You could still make your own url if only you know what you are doing.
|
48
|
+
|
49
|
+
#### Test
|
50
|
+
1. Update connection settings in `spec/spec_helper.rb`:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# Aliyun defaults
|
54
|
+
OSS_CONNECTION_OPTIONS = {
|
55
|
+
access_id: 'your_access_key_id',
|
56
|
+
access_key: 'your_access_key_secret',
|
57
|
+
bucket: 'your_bucket',
|
58
|
+
data_center: 'your_data_center',
|
59
|
+
internal: false
|
60
|
+
}
|
61
|
+
```
|
62
|
+
|
63
|
+
2. Run `bundle exec rspec spec`.
|
data/lib/aliyun/connection.rb
CHANGED
@@ -93,7 +93,7 @@ module Aliyun
|
|
93
93
|
'Host' => @aliyun_upload_host,
|
94
94
|
'Expect' => '100-Continue'
|
95
95
|
}
|
96
|
-
response = RestClient.put(
|
96
|
+
response = RestClient.put(url, file, headers)
|
97
97
|
response.code == 200 ? path_to_url(path) : nil
|
98
98
|
end
|
99
99
|
|
@@ -113,7 +113,7 @@ module Aliyun
|
|
113
113
|
'Authorization' => sign('DELETE', bucket_path, '', '', date)
|
114
114
|
}
|
115
115
|
url = path_to_url(path)
|
116
|
-
response = RestClient.delete(
|
116
|
+
response = RestClient.delete(url, headers)
|
117
117
|
response.code == 204 ? url : nil
|
118
118
|
end
|
119
119
|
|
@@ -132,7 +132,7 @@ module Aliyun
|
|
132
132
|
'Authorization' => sign('GET', bucket_path, '', '', date)
|
133
133
|
}
|
134
134
|
url = path_to_url(path)
|
135
|
-
response = RestClient.get(
|
135
|
+
response = RestClient.get(url, headers)
|
136
136
|
response.body
|
137
137
|
end
|
138
138
|
|
@@ -176,7 +176,7 @@ module Aliyun
|
|
176
176
|
# @param path [String] the path to retrieve the file on remote storage
|
177
177
|
# @return [String] the expected full path, e.g. "http://martin-test.oss-cn-hangzhou.aliyuncs.com/oss-api.pdf"
|
178
178
|
def path_to_url(path)
|
179
|
-
path =~ %r{^https?://} ? path : "http://#{aliyun_upload_host}/#{path}"
|
179
|
+
URI.encode(path =~ %r{^https?://} ? path : "http://#{aliyun_upload_host}/#{path}")
|
180
180
|
end
|
181
181
|
|
182
182
|
private
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.require_path = 'lib'
|
5
5
|
s.summary = 'Extend a Aliyun OSS storage for paperclip'
|
6
6
|
s.description = 'Extend a Aliyun OSS storage for paperclip'
|
7
|
-
s.version = '0.1.
|
7
|
+
s.version = '0.1.1'
|
8
8
|
s.files = `git ls-files`.split("\n")
|
9
9
|
s.authors = ['Martin Hong', 'Aidi Stan']
|
10
10
|
s.email = 'hongzeqin@gmail.com'
|
data/spec/aliyun_spec.rb
CHANGED
@@ -40,11 +40,23 @@ describe Aliyun::Connection do
|
|
40
40
|
response_code = Net::HTTP.get_response(URI.parse(url)).code
|
41
41
|
expect(response_code).to eq('404')
|
42
42
|
end
|
43
|
+
|
44
|
+
describe "delete attachment with Chinese name" do
|
45
|
+
it "delete the attachment" do
|
46
|
+
path = "a/美女.jpg"
|
47
|
+
@connection.put path, load_attachment('美女.jpg')
|
48
|
+
url = @connection.delete path
|
49
|
+
response_code = Net::HTTP.get_response(URI.parse(url)).code
|
50
|
+
expect(response_code).to eq('404')
|
51
|
+
end
|
52
|
+
end
|
43
53
|
end
|
44
54
|
|
45
55
|
describe '#exists?' do
|
46
56
|
before :all do
|
47
57
|
@connection.put @path, load_attachment('girl.jpg')
|
58
|
+
@path_include_chinese = "美女.jpg"
|
59
|
+
@connection.put @path_include_chinese, load_attachment("美女.jpg")
|
48
60
|
end
|
49
61
|
|
50
62
|
it 'return true if the file has been uploaded' do
|
@@ -55,5 +67,11 @@ describe Aliyun::Connection do
|
|
55
67
|
@connection.delete @path
|
56
68
|
expect(@connection.exists?(@path)).to be_falsey
|
57
69
|
end
|
70
|
+
|
71
|
+
it "also return true for existed file with path include chinese characters" do
|
72
|
+
expect(@connection.exists?(@path_include_chinese)).to be_truthy
|
73
|
+
url = "http://#{@connection.aliyun_upload_host}/#{@path_include_chinese}"
|
74
|
+
expect(@connection.exists?(url)).to be_truthy
|
75
|
+
end
|
58
76
|
end
|
59
77
|
end
|
Binary file
|
@@ -69,5 +69,19 @@ describe Paperclip::Storage::Aliyun do
|
|
69
69
|
response_code = Net::HTTP.get_response(URI.parse(attachment_url)).code
|
70
70
|
expect(response_code).to eq('404')
|
71
71
|
end
|
72
|
+
|
73
|
+
context "work with path include Chinese characters" do
|
74
|
+
before do
|
75
|
+
@file_with_chinese_char_name = load_attachment("美女.jpg")
|
76
|
+
@post_with_chinese_char_name_file = Post.create attachment: @file_with_chinese_char_name
|
77
|
+
end
|
78
|
+
|
79
|
+
it "deletes the attachment from Aliyun" do
|
80
|
+
attachment_url = @post_with_chinese_char_name_file.attachment.url
|
81
|
+
@post_with_chinese_char_name_file.destroy
|
82
|
+
response_code = Net::HTTP.get_response(URI.parse(attachment_url)).code
|
83
|
+
expect(response_code).to eq('404')
|
84
|
+
end
|
85
|
+
end
|
72
86
|
end
|
73
87
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,8 +7,8 @@ Dir[Bundler.root.join('spec/support/**/*.rb')].each(&method(:require))
|
|
7
7
|
|
8
8
|
# Aliyun defaults
|
9
9
|
OSS_CONNECTION_OPTIONS = {
|
10
|
-
access_id: '
|
11
|
-
access_key: '
|
10
|
+
access_id: '4adTRa4dWto3vxiq',
|
11
|
+
access_key: 'hzEWBDWlt3N0SPPj6EfYAr4ISdaizW',
|
12
12
|
bucket: 'martin-test',
|
13
13
|
data_center: 'hangzhou',
|
14
14
|
internal: false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-storage-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
|
- Martin Hong
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- spec/aliyun_spec.rb
|
61
61
|
- spec/attachments/girl.jpg
|
62
62
|
- spec/attachments/masu.pdf
|
63
|
+
- spec/attachments/美女.jpg
|
63
64
|
- spec/fixtures/schema.rb
|
64
65
|
- spec/lib/paperclip/storage/aliyun_spec.rb
|
65
66
|
- spec/spec_helper.rb
|
@@ -90,4 +91,3 @@ signing_key:
|
|
90
91
|
specification_version: 4
|
91
92
|
summary: Extend a Aliyun OSS storage for paperclip
|
92
93
|
test_files: []
|
93
|
-
has_rdoc:
|