carrierwave-upyun 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/lib/carrierwave-upyun.rb +4 -2
- data/lib/carrierwave/storage/upyun.rb +41 -36
- data/lib/carrierwave/upyun/configuration.rb +6 -4
- metadata +2 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f791f761160e72a58c354c42e721eafa4a7f832eb5ecc5b7bc79a8a870c852b9
|
4
|
+
data.tar.gz: 9af67d6bdf3b6b82cc8e237b4e867a08fdc27e595c90e20b5a8630b3defffdc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd03f1cbf3f23f5df6cb1015508d7e29406f2eb55eccf7170417be372220d0eedc59323b9c853473013a094fb55923065572d64e843afc195166d5e478413fb
|
7
|
+
data.tar.gz: a2090f8fd7154ddefbc43914d11929a7f1871e38eea1b0a7bbbd81557053eb88273164120f2b8c785e0f58271e1f8eb58f78b0c8f397d0fb7f596cb42ea9928f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.0.1
|
2
|
+
|
3
|
+
- 对于 CarrierWave 的 cache 机制正确支持;
|
4
|
+
- 对 UpYun 偶发的 `concurrent put or delete` 错误容错;
|
5
|
+
- 清理不必要的 dependency.
|
6
|
+
|
7
|
+
## 1.0.0
|
8
|
+
|
9
|
+
- 支持 CarrierWave 2.0.0+;
|
10
|
+
|
1
11
|
## 0.2.2
|
2
12
|
|
3
13
|
- 减少 Gem 文件尺寸,避免带入不必要的问题;
|
@@ -24,4 +34,4 @@
|
|
24
34
|
|
25
35
|
## 0.1.6
|
26
36
|
|
27
|
-
- 改进 Upyun 初始化,将少连接的过程;
|
37
|
+
- 改进 Upyun 初始化,将少连接的过程;
|
data/lib/carrierwave-upyun.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "carrierwave/storage/upyun"
|
2
4
|
require "carrierwave/upyun/configuration"
|
3
5
|
|
4
6
|
CarrierWave.configure do |config|
|
5
|
-
config.storage_engines.merge!(
|
7
|
+
config.storage_engines.merge!(upyun: "CarrierWave::Storage::UpYun")
|
6
8
|
end
|
7
9
|
|
8
|
-
CarrierWave::Uploader::Base.
|
10
|
+
CarrierWave::Uploader::Base.include CarrierWave::UpYun::Configuration
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "faraday"
|
3
4
|
|
4
5
|
module CarrierWave
|
@@ -15,7 +16,10 @@ module CarrierWave
|
|
15
16
|
#
|
16
17
|
#
|
17
18
|
class UpYun < Abstract
|
18
|
-
DEFAULT_API_URL =
|
19
|
+
DEFAULT_API_URL = "http://v0.api.upyun.com"
|
20
|
+
|
21
|
+
class UploadError < RuntimeError; end
|
22
|
+
class ConcurrentUploadError < RuntimeError; end
|
19
23
|
|
20
24
|
class File < CarrierWave::SanitizedFile
|
21
25
|
def initialize(uploader, base, path)
|
@@ -31,9 +35,7 @@ module CarrierWave
|
|
31
35
|
#
|
32
36
|
# [String] A path
|
33
37
|
#
|
34
|
-
|
35
|
-
@path
|
36
|
-
end
|
38
|
+
attr_reader :path
|
37
39
|
|
38
40
|
def escaped_path
|
39
41
|
@escaped_path ||= CGI.escape(@path)
|
@@ -43,9 +45,7 @@ module CarrierWave
|
|
43
45
|
@content_type || ""
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
@content_type = new_content_type
|
48
|
-
end
|
48
|
+
attr_writer :content_type
|
49
49
|
|
50
50
|
##
|
51
51
|
# Reads the contents of the file from Cloud Files
|
@@ -64,13 +64,11 @@ module CarrierWave
|
|
64
64
|
# Remove the file from Cloud Files
|
65
65
|
#
|
66
66
|
def delete
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
nil
|
73
|
-
end
|
67
|
+
conn.delete(escaped_path)
|
68
|
+
true
|
69
|
+
rescue StandardError => e
|
70
|
+
puts "carrierwave-upyun delete failed: #{e.inspect}"
|
71
|
+
nil
|
74
72
|
end
|
75
73
|
|
76
74
|
##
|
@@ -83,6 +81,7 @@ module CarrierWave
|
|
83
81
|
#
|
84
82
|
def url
|
85
83
|
return nil unless @uploader.upyun_bucket_host
|
84
|
+
|
86
85
|
[@uploader.upyun_bucket_host, @path].join("/")
|
87
86
|
end
|
88
87
|
|
@@ -101,34 +100,42 @@ module CarrierWave
|
|
101
100
|
#
|
102
101
|
# boolean
|
103
102
|
#
|
104
|
-
def store(
|
105
|
-
res = conn.put(escaped_path,
|
106
|
-
req.headers = {
|
103
|
+
def store(new_file, headers = {})
|
104
|
+
res = conn.put(escaped_path, new_file.read) do |req|
|
105
|
+
req.headers = { "Expect" => "", "Mkdir" => "true" }.merge(headers)
|
107
106
|
end
|
107
|
+
|
108
108
|
if res.status != 200
|
109
|
-
|
110
|
-
|
109
|
+
# code: 42900007 -> concurrent put or delete
|
110
|
+
json = JSON.parse(res.body)
|
111
|
+
# retry upload
|
112
|
+
raise ConcurrentUploadError, res.body if json["code"] == 42_900_007
|
113
|
+
|
114
|
+
raise UploadError, res.body
|
111
115
|
end
|
112
116
|
|
113
117
|
true
|
118
|
+
rescue ConcurrentUploadError => e
|
119
|
+
puts "Warning: UpYun error #{e.message}, retry again."
|
120
|
+
retry
|
114
121
|
end
|
115
122
|
|
116
123
|
def headers
|
117
124
|
@headers ||= begin
|
118
125
|
conn.get(@path).headers
|
119
|
-
|
120
|
-
|
126
|
+
rescue Faraday::ClientError
|
127
|
+
{}
|
121
128
|
end
|
122
129
|
end
|
123
130
|
|
124
131
|
def conn
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
+
@conn ||= begin
|
133
|
+
api_host = @uploader.upyun_api_host || DEFAULT_API_URL
|
134
|
+
Faraday.new(url: "#{api_host}/#{@uploader.upyun_bucket}") do |req|
|
135
|
+
req.request :basic_auth, @uploader.upyun_username, @uploader.upyun_password
|
136
|
+
req.request :url_encoded
|
137
|
+
req.adapter Faraday.default_adapter
|
138
|
+
end
|
132
139
|
end
|
133
140
|
end
|
134
141
|
end # File
|
@@ -146,7 +153,7 @@ module CarrierWave
|
|
146
153
|
#
|
147
154
|
def store!(file)
|
148
155
|
f = File.new(uploader, self, uploader.store_path)
|
149
|
-
f.store(file
|
156
|
+
f.store(file, "Content-Type" => file.content_type)
|
150
157
|
f
|
151
158
|
end
|
152
159
|
|
@@ -165,8 +172,8 @@ module CarrierWave
|
|
165
172
|
end
|
166
173
|
|
167
174
|
def cache!(file)
|
168
|
-
f = File.new(uploader, self, uploader.
|
169
|
-
f.store(file
|
175
|
+
f = File.new(uploader, self, uploader.cache_path)
|
176
|
+
f.store(file, "Content-Type" => file.content_type)
|
170
177
|
f
|
171
178
|
end
|
172
179
|
|
@@ -174,11 +181,9 @@ module CarrierWave
|
|
174
181
|
File.new(uploader, self, uploader.cache_path(identifier))
|
175
182
|
end
|
176
183
|
|
177
|
-
def delete_dir!(path)
|
178
|
-
end
|
184
|
+
def delete_dir!(path); end
|
179
185
|
|
180
|
-
def clean_cache!(seconds)
|
181
|
-
end
|
186
|
+
def clean_cache!(seconds); end
|
182
187
|
end # CloudFiles
|
183
188
|
end # Storage
|
184
189
|
end # CarrierWave
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CarrierWave
|
2
4
|
module UpYun
|
3
5
|
module Configuration
|
@@ -10,13 +12,13 @@ module CarrierWave
|
|
10
12
|
add_config :upyun_bucket_host
|
11
13
|
end
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
module ClassMethods
|
15
17
|
def add_config(name)
|
16
18
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
17
19
|
def self.#{name}(value=nil)
|
18
20
|
@#{name} = value if value
|
19
|
-
return @#{name} if self.object_id == #{
|
21
|
+
return @#{name} if self.object_id == #{object_id} || defined?(@#{name})
|
20
22
|
name = superclass.#{name}
|
21
23
|
return nil if name.nil? && !instance_variable_defined?("@#{name}")
|
22
24
|
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
@@ -31,7 +33,7 @@ module CarrierWave
|
|
31
33
|
value.instance_of?(Proc) ? value.call : value
|
32
34
|
end
|
33
35
|
RUBY
|
34
|
-
end
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
|
-
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-upyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nowa Zhu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -45,76 +45,6 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.8.0
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: sqlite3
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: activerecord
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
type: :development
|
70
|
-
prerelease: false
|
71
|
-
version_requirements: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: sqlite3-ruby
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
type: :development
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: mini_magick
|
92
|
-
requirement: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
type: :development
|
98
|
-
prerelease: false
|
99
|
-
version_requirements: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
- !ruby/object:Gem::Dependency
|
105
|
-
name: rspec
|
106
|
-
requirement: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
type: :development
|
112
|
-
prerelease: false
|
113
|
-
version_requirements: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
48
|
description: UpYun Storage support for CarrierWave
|
119
49
|
email:
|
120
50
|
- nowazhu@gmail.com
|