carrierwave-aliyun 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03a96d213f40d85c4e9cb135f1e32490fd3dcd2c38e1fe4c5fb866a0c06f8813
4
- data.tar.gz: 372720e762645aed633542bce67a177b1718a1282ddf0012ca8d52eab554718d
3
+ metadata.gz: '09185a0291f96fed424df86a4be3815f13171b74f4b6d891b945de90bdc3924d'
4
+ data.tar.gz: ff50669bd39b9da0ff3b9c5c00c9e646fc0f3f46e7f0b1b45643c9d76abe66fd
5
5
  SHA512:
6
- metadata.gz: a4957fb8b0998385cd932c142688cfd6dd8a2d9a971822a0fbf345e26382f2b44055e9a68e59a6ebc9c2ffae64a225eac6e30b97e43c4499ba177684982d38c0
7
- data.tar.gz: 808b8d986b14cf9fcc25fd551c752a81e55bf59cd42db1b08b3c124a0de920254ea1f79fa5ca91a6c45ace1078716c097579f15f824edfa1117f5229a1b0c6db
6
+ metadata.gz: fd28e434c5bd6d43ccfff8f5b98dff4343d1440c3ded461397b95bde45e280bfde4481e0c06d0af3da8d38009620546c36cd777fd5c6bae893038e94533cc8ba
7
+ data.tar.gz: 88a37bc5bbf656be44cb50232943faac2ba26698fdee306f3441f0365e853066fdfb97297b9c7c0012d256ba80f02b69f78af8e585938de7917926dfa473f4a1
@@ -1,5 +1,10 @@
1
1
  ## 1.2.1
2
2
 
3
+ - 修正 #79 某些场景中文文件名无法正确上传的问题;
4
+ - 修正 #70 上传文件以后 tmp 目录依然还残留着 cache 文件的问题;
5
+
6
+ ## 1.2.1
7
+
3
8
  - 实现 `size` 方法,修正更新图片数组时,新上传的图片会取代旧图片的问题。(#73)
4
9
 
5
10
  ## 1.2.0
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This gem adds support for [Aliyun OSS](http://oss.aliyun.com) to [CarrierWave](https://github.com/jnicklas/carrierwave/)
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/carrierwave-aliyun.svg)](https://rubygems.org/gems/carrierwave-aliyun) [![Build Status](https://travis-ci.org/huacnlee/carrierwave-aliyun.svg?branch=master)](https://travis-ci.org/huacnlee/carrierwave-aliyun) [![Code Climate](https://codeclimate.com/github/huacnlee/carrierwave-aliyun/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/carrierwave-aliyun)
5
+ [![Gem Version](https://badge.fury.io/rb/carrierwave-aliyun.svg)](https://rubygems.org/gems/carrierwave-aliyun) [![build](https://github.com/huacnlee/carrierwave-aliyun/workflows/build/badge.svg)](https://github.com/huacnlee/carrierwave-aliyun/actions?query=workflow%3Abuild)
6
6
 
7
7
  > NOTE: 此 Gem 是一个 CarrierWave 的组件,你需要配合 CarrierWave 一起使用,如果你需要直接用 Aliyun OSS,可以尝试用 [aliyun-sdk](https://github.com/aliyun/aliyun-oss-ruby-sdk) 这个 Gem。
8
8
 
@@ -6,9 +6,8 @@ module CarrierWave
6
6
  PATH_PREFIX = %r{^/}.freeze
7
7
  CHUNK_SIZE = 1024 * 1024
8
8
 
9
- attr_reader :access_key_id, :access_key_secret, :bucket, :region, :mode, :host
10
-
11
- attr_reader :endpoint, :upload_endpoint, :get_endpoint
9
+ attr_reader :access_key_id, :access_key_secret, :bucket, :region, :mode, :host, :endpoint, :upload_endpoint,
10
+ :get_endpoint
12
11
 
13
12
  def initialize(uploader)
14
13
  if uploader.aliyun_area.present?
@@ -137,9 +136,7 @@ module CarrierWave
137
136
  oss_client.object_url(path, private, 15.minutes)
138
137
  end
139
138
 
140
- unless private
141
- url = [url, thumb].join("") unless thumb&.start_with?("?")
142
- end
139
+ url = [url, thumb].join("") if !private && !thumb&.start_with?("?")
143
140
 
144
141
  url.sub(endpoint, host)
145
142
  end
@@ -149,19 +146,26 @@ module CarrierWave
149
146
  oss_upload_client.get_object(path)
150
147
  end
151
148
 
149
+ # list_objects for test
150
+ def list_objects(opts = {})
151
+ oss_client.list_objects(opts)
152
+ end
153
+
152
154
  private
153
155
 
154
156
  def oss_client
155
157
  return @oss_client if defined?(@oss_client)
156
158
 
157
- client = ::Aliyun::OSS::Client.new(endpoint: get_endpoint, access_key_id: access_key_id, access_key_secret: access_key_secret)
159
+ client = ::Aliyun::OSS::Client.new(endpoint: get_endpoint, access_key_id: access_key_id,
160
+ access_key_secret: access_key_secret)
158
161
  @oss_client = client.get_bucket(bucket)
159
162
  end
160
163
 
161
164
  def oss_upload_client
162
165
  return @oss_upload_client if defined?(@oss_upload_client)
163
166
 
164
- client = ::Aliyun::OSS::Client.new(endpoint: upload_endpoint, access_key_id: access_key_id, access_key_secret: access_key_secret)
167
+ client = ::Aliyun::OSS::Client.new(endpoint: upload_endpoint, access_key_id: access_key_id,
168
+ access_key_secret: access_key_secret)
165
169
  @oss_upload_client = client.get_bucket(bucket)
166
170
  end
167
171
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CarrierWave
4
4
  module Aliyun
5
- VERSION = "1.2.1"
5
+ VERSION = "1.2.2"
6
6
  end
7
7
  end
@@ -37,22 +37,11 @@ module CarrierWave
37
37
  # do nothing, because there's no such things as 'empty directory'
38
38
  end
39
39
 
40
- def clean_cache!(_seconds)
41
- will_remove_keys = []
42
- bucket.list_objects(prefix: uploader.cache_path).each do |file|
43
- next unless file.is_a?(Object)
44
- time = file.key.scan(/(\d+)-\d+-\d+(?:-\d+)?/).first.map { |t| t.to_i }
45
- time = Time.at(*time)
46
- will_remove_keys << item.key if time < (Time.now.utc - seconds)
47
- end
48
- bucket.batch_delete_objects(will_remove_keys)
49
- end
50
-
51
40
  private
52
41
 
53
- def bucket
54
- @bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
55
- end
42
+ def bucket
43
+ @bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
44
+ end
56
45
  end
57
46
  end
58
47
  end
@@ -6,11 +6,13 @@ module CarrierWave
6
6
  attr_writer :file
7
7
  attr_reader :uploader, :path
8
8
 
9
- alias_method :filename, :path
10
- alias_method :identifier, :filename
9
+ alias filename path
10
+ alias identifier filename
11
11
 
12
12
  def initialize(uploader, base, path)
13
- @uploader, @path, @base = uploader, escape(path), base
13
+ @uploader = uploader
14
+ @path = path
15
+ @base = base
14
16
  end
15
17
 
16
18
  def file
@@ -18,11 +20,9 @@ module CarrierWave
18
20
  end
19
21
 
20
22
  def size
21
- file.headers[:content_length].to_i rescue nil
22
- end
23
-
24
- def escape(path)
25
- CGI.escape(path).gsub("%2F", "/")
23
+ file.headers[:content_length].to_i
24
+ rescue StandardError
25
+ nil
26
26
  end
27
27
 
28
28
  def read
@@ -34,7 +34,7 @@ module CarrierWave
34
34
  def delete
35
35
  bucket.delete(path)
36
36
  true
37
- rescue => e
37
+ rescue StandardError => e
38
38
  # If the file's not there, don't panic
39
39
  puts "carrierwave-aliyun delete file failed: #{e}"
40
40
  nil
@@ -95,7 +95,8 @@ module CarrierWave
95
95
 
96
96
  def original_filename
97
97
  return @original_filename if @original_filename
98
- if @file && @file.respond_to?(:original_filename)
98
+
99
+ if @file&.respond_to?(:original_filename)
99
100
  @file.original_filename
100
101
  elsif path
101
102
  ::File.basename(path)
@@ -104,9 +105,9 @@ module CarrierWave
104
105
 
105
106
  private
106
107
 
107
- def bucket
108
- @bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
109
- end
108
+ def bucket
109
+ @bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
110
+ end
110
111
  end
111
112
  end
112
113
  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: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.1.4
75
+ rubygems_version: 3.2.3
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Aliyun OSS support for Carrierwave