carrierwave-aliyun 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelogs.md +5 -0
- data/README.md +5 -1
- data/carrierwave-aliyun.gemspec +2 -1
- data/lib/carrierwave/aliyun/version.rb +32 -0
- data/lib/carrierwave/storage/aliyun.rb +35 -10
- data/spec/aliyun_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -3
- data/spec/upload_spec.rb +7 -0
- metadata +16 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de75b74723a825b2db59c61c2062cc57847ec4d2
|
4
|
+
data.tar.gz: 2b96649234614f4fbc559ba2e4be3daafdb7d861
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c2c7d7be67f169d47144e3eb8a061efe8127ba1e9c94ff33b4324b0cfb449d859ca73fc301d6656b4ddf5b22c321ffa2d67e8b95a2dfb402aec27bb4a61b30b
|
7
|
+
data.tar.gz: c1d55f78f3a70c9bba297e4fb5a38e87863b555b5c8bfa5762519c0979c256be51319fe975f314a7a480dd4e8a7239d3054120bd52b2992da001e53ce1f16627
|
data/Changelogs.md
CHANGED
data/README.md
CHANGED
data/carrierwave-aliyun.gemspec
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require File.expand_path('lib/carrierwave/aliyun/version')
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
6
|
s.name = "carrierwave-aliyun"
|
6
|
-
s.version =
|
7
|
+
s.version = CarrierWave::Aliyun::Version.current
|
7
8
|
s.platform = Gem::Platform::RUBY
|
8
9
|
s.authors = ["Jason Lee"]
|
9
10
|
s.email = ["huacnlee@gmail.com"]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Aliyun
|
3
|
+
class Version
|
4
|
+
MAJOR, MINOR, PATCH = 0, 1, 3
|
5
|
+
|
6
|
+
##
|
7
|
+
# Returns the major version ( big release based off of multiple minor releases )
|
8
|
+
def self.major
|
9
|
+
MAJOR
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Returns the minor version ( small release based off of multiple patches )
|
14
|
+
def self.minor
|
15
|
+
MINOR
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Returns the patch version ( updates, features and (crucial) bug fixes )
|
20
|
+
def self.patch
|
21
|
+
PATCH
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns the current version of the Backup gem ( qualified for the gemspec )
|
26
|
+
def self.current
|
27
|
+
"#{major}.#{minor}.#{patch}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -19,26 +19,50 @@ module CarrierWave
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def put(path,
|
23
|
-
|
22
|
+
def put(path, file_data, options={})
|
23
|
+
path = format_path(path)
|
24
|
+
content_md5 = Digest::MD5.hexdigest(file_data)
|
24
25
|
content_type = options[:content_type] || "image/jpg"
|
25
|
-
date =
|
26
|
-
|
27
|
-
|
28
|
-
auth_sign = sign("PUT", path, content_md5, content_type ,date)
|
26
|
+
date = gmtdate
|
27
|
+
url = path_to_url(path)
|
28
|
+
auth_sign = sign("PUT", path, content_md5, content_type,date)
|
29
29
|
headers = {
|
30
30
|
"Authorization" => auth_sign,
|
31
31
|
"Content-Type" => content_type,
|
32
|
-
"Content-Length" =>
|
32
|
+
"Content-Length" => file_data.length,
|
33
33
|
"Date" => date,
|
34
34
|
"Host" => @aliyun_host,
|
35
35
|
"Expect" => "100-Continue"
|
36
36
|
}
|
37
|
-
response = RestClient.put(url,
|
37
|
+
response = RestClient.put(url, file_data, headers)
|
38
|
+
return url
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
|
41
|
+
def delete(path)
|
42
|
+
path = format_path(path)
|
43
|
+
date = gmtdate
|
44
|
+
headers = {
|
45
|
+
"Host" => @aliyun_host,
|
46
|
+
"Date" => date,
|
47
|
+
"Authorization" => sign("DELETE", path, "", "" ,date)
|
48
|
+
}
|
49
|
+
url = path_to_url(path)
|
50
|
+
RestClient.delete(url, headers)
|
51
|
+
return url
|
52
|
+
end
|
53
|
+
|
54
|
+
def gmtdate
|
55
|
+
Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
56
|
+
end
|
57
|
+
|
58
|
+
def format_path(path)
|
59
|
+
return "" if path.blank?
|
60
|
+
path.gsub!(/^\//,"")
|
61
|
+
[@aliyun_bucket, path].join("/")
|
62
|
+
end
|
63
|
+
|
64
|
+
def path_to_url(path)
|
65
|
+
"http://#{@aliyun_host}/#{path}"
|
42
66
|
end
|
43
67
|
|
44
68
|
private
|
@@ -92,6 +116,7 @@ module CarrierWave
|
|
92
116
|
true
|
93
117
|
rescue Exception => e
|
94
118
|
# If the file's not there, don't panic
|
119
|
+
puts "carrierwave-aliyun delete file failed: #{e}"
|
95
120
|
nil
|
96
121
|
end
|
97
122
|
end
|
data/spec/aliyun_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require "open-uri"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
describe "Aliyun" do
|
6
|
+
before(:all) do
|
7
|
+
opts = {
|
8
|
+
:aliyun_access_id => ALIYUN_ACCESS_ID,
|
9
|
+
:aliyun_access_key => ALIYUN_ACCESS_KEY,
|
10
|
+
:aliyun_bucket => ALIYUN_BUCKET
|
11
|
+
}
|
12
|
+
@connection = CarrierWave::Storage::Aliyun::Connection.new(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should put" do
|
16
|
+
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
17
|
+
Net::HTTP.get_response(URI.parse(url)).code.should == "200"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should put with / prefix" do
|
21
|
+
url = @connection.put("/a/a.jpg",load_file("foo.jpg").read)
|
22
|
+
Net::HTTP.get_response(URI.parse(url)).code.should == "200"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should delete" do
|
26
|
+
url = @connection.delete("/a/a.jpg")
|
27
|
+
Net::HTTP.get_response(URI.parse(url)).code.should == "404"
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,11 +24,15 @@ end
|
|
24
24
|
ActiveRecord::Migration.verbose = false
|
25
25
|
|
26
26
|
# 测试的时候需要修改这个地方
|
27
|
+
ALIYUN_ACCESS_ID = "7ewl4zm3mhi45vko9zx022ul"
|
28
|
+
ALIYUN_ACCESS_KEY = 'Ajpi7IRKDKdXYHHFFoS89uQJQE8='
|
29
|
+
ALIYUN_BUCKET = "carrierwave"
|
30
|
+
|
27
31
|
CarrierWave.configure do |config|
|
28
32
|
config.storage = :aliyun
|
29
|
-
config.aliyun_access_id =
|
30
|
-
config.aliyun_access_key =
|
31
|
-
config.aliyun_bucket =
|
33
|
+
config.aliyun_access_id = ALIYUN_ACCESS_ID
|
34
|
+
config.aliyun_access_key = ALIYUN_ACCESS_KEY
|
35
|
+
config.aliyun_bucket = ALIYUN_BUCKET
|
32
36
|
# config.aliyun_internal = false
|
33
37
|
end
|
34
38
|
|
data/spec/upload_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
require "open-uri"
|
4
|
+
require "net/http"
|
4
5
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
5
6
|
|
6
7
|
describe "Upload" do
|
@@ -101,6 +102,12 @@ describe "Upload" do
|
|
101
102
|
attach.size.should == @file.size
|
102
103
|
end
|
103
104
|
|
105
|
+
it "should delete old file when upload a new file again" do
|
106
|
+
old_url = @attachment.file.url
|
107
|
+
@attachment.file = load_file("foo.gif")
|
108
|
+
@attachment.save
|
109
|
+
Net::HTTP.get_response(URI.parse(old_url)).code.should == "404"
|
110
|
+
end
|
104
111
|
end
|
105
112
|
end
|
106
113
|
end
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jason Lee
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: carrierwave
|
16
|
-
prerelease: false
|
17
15
|
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.5.7
|
22
|
-
none: false
|
23
20
|
type: :runtime
|
21
|
+
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - '>='
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: 0.5.7
|
29
|
-
none: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
|
-
prerelease: false
|
33
29
|
requirement: !ruby/object:Gem::Requirement
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 1.6.7
|
38
|
-
none: false
|
39
34
|
type: :runtime
|
35
|
+
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- -
|
38
|
+
- - '>='
|
43
39
|
- !ruby/object:Gem::Version
|
44
40
|
version: 1.6.7
|
45
|
-
none: false
|
46
41
|
description: Aliyun OSS support for Carrierwave
|
47
42
|
email:
|
48
43
|
- huacnlee@gmail.com
|
@@ -59,7 +54,9 @@ files:
|
|
59
54
|
- carrierwave-aliyun.gemspec
|
60
55
|
- lib/carrierwave-aliyun.rb
|
61
56
|
- lib/carrierwave/aliyun/configuration.rb
|
57
|
+
- lib/carrierwave/aliyun/version.rb
|
62
58
|
- lib/carrierwave/storage/aliyun.rb
|
59
|
+
- spec/aliyun_spec.rb
|
63
60
|
- spec/foo.gif
|
64
61
|
- spec/foo.jpg
|
65
62
|
- spec/foo.zip
|
@@ -67,29 +64,29 @@ files:
|
|
67
64
|
- spec/upload_spec.rb
|
68
65
|
homepage: https://github.com/nowa/carrierwave-aliyun
|
69
66
|
licenses: []
|
67
|
+
metadata: {}
|
70
68
|
post_install_message:
|
71
69
|
rdoc_options: []
|
72
70
|
require_paths:
|
73
71
|
- lib
|
74
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
73
|
requirements:
|
76
|
-
- -
|
74
|
+
- - '>='
|
77
75
|
- !ruby/object:Gem::Version
|
78
76
|
version: '0'
|
79
|
-
none: false
|
80
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
78
|
requirements:
|
82
|
-
- -
|
79
|
+
- - '>='
|
83
80
|
- !ruby/object:Gem::Version
|
84
81
|
version: '0'
|
85
|
-
none: false
|
86
82
|
requirements: []
|
87
83
|
rubyforge_project:
|
88
|
-
rubygems_version:
|
84
|
+
rubygems_version: 2.0.2
|
89
85
|
signing_key:
|
90
|
-
specification_version:
|
86
|
+
specification_version: 4
|
91
87
|
summary: Aliyun OSS support for Carrierwave
|
92
88
|
test_files:
|
89
|
+
- spec/aliyun_spec.rb
|
93
90
|
- spec/foo.gif
|
94
91
|
- spec/foo.jpg
|
95
92
|
- spec/foo.zip
|