activestorage-openstack 1.1.0 → 1.4.2

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
  SHA256:
3
- metadata.gz: '08cb71cda986de0a17ccb980ce6ff47269904271b531bc180096feb482f1fad4'
4
- data.tar.gz: 37d0306d80d740309e78e572654feb170ac77dd6fba0e0381bc13f54f5bc0b80
3
+ metadata.gz: cce4c99f0a5a3c5cbdef328ae3633196657a04a8c9ba801fe82904b1f0283abf
4
+ data.tar.gz: 2cf3bcee0842a884a11ae611e7c39cd0a059e690cb2f9872e647999274b68490
5
5
  SHA512:
6
- metadata.gz: cfaad4fba29cd40fb8f1e17dd917b442bf5759ba740f0a90f8ccb23a5ba2fe56693bd96d6d2973fd0cc4da59b88fcae6a1b52df575a6d48f3fafb4639e013232
7
- data.tar.gz: e31cf4aa8e0925af9357bf9c814533f08222436bf6e0f1041067120d8742a8910bbfa89ef9f578b32d542204362a20f7a6246710158e506346c62e93af045a9c
6
+ metadata.gz: 9a467d3b91dd8c2be7cad76e02f223b43bb4ccbe82b26b19459fb9388f7c21e2e5d31ce051ab325d225159c377157fb96d3701d58b2e0b870edeb4aea5ea2660
7
+ data.tar.gz: a4ee1f33629ee2ad84ccba999290f27c495a412e867242a97ff5952e2dde22baab641ad1600db2afa47b2aa671f6a22917a79cd576168cd38bf349b246923788
@@ -1,18 +1,6 @@
1
1
  module ActiveStorage
2
2
  module Openstack
3
3
  class Railtie < ::Rails::Railtie
4
- initializer "active_storage_openstack.blob" do
5
- ActiveSupport.on_load(:active_storage_blob) do |klass|
6
- klass.after_commit do |blob|
7
- # overwrite content type if identification run and
8
- # the service responds to change_content_type
9
- if blob.identified? && !blob.content_type.blank? &&
10
- blob.service.respond_to?(:change_content_type)
11
- blob.service.change_content_type(blob.key, blob.content_type)
12
- end
13
- end
14
- end
15
- end
16
4
  end
17
5
  end
18
6
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveStorage
2
2
  module Openstack
3
- VERSION = '1.1.0'
3
+ VERSION = '1.4.2'
4
4
  end
5
5
  end
@@ -11,10 +11,14 @@ module ActiveStorage
11
11
  @container = Fog::OpenStack.escape(container)
12
12
  end
13
13
 
14
- def upload(key, io, checksum: nil, **)
14
+ def upload(key, io, checksum: nil, disposition: nil, content_type: nil, filename: nil, **)
15
15
  instrument :upload, key: key, checksum: checksum do
16
- params = { 'Content-Type' => guess_content_type(io) }
16
+ params = { 'Content-Type' => content_type || guess_content_type(io) }
17
17
  params['ETag'] = convert_base64digest_to_hexdigest(checksum) if checksum
18
+ if disposition && filename
19
+ params['Content-Disposition'] =
20
+ content_disposition_with(type: disposition, filename: filename)
21
+ end
18
22
 
19
23
  begin
20
24
  client.put_object(container, key, io, params)
@@ -35,7 +39,7 @@ module ActiveStorage
35
39
  end
36
40
  end
37
41
  rescue Fog::OpenStack::Storage::NotFound
38
- raise ActiveStorage::FileNotFoundError
42
+ raise ActiveStorage::FileNotFoundError if defined?(ActiveStorage::FileNotFoundError)
39
43
  end
40
44
 
41
45
  def download_chunk(key, range)
@@ -48,16 +52,15 @@ module ActiveStorage
48
52
 
49
53
  chunk_buffer.join[range]
50
54
  rescue Fog::OpenStack::Storage::NotFound
51
- raise ActiveStorage::FileNotFoundError
55
+ raise ActiveStorage::FileNotFoundError if defined?(ActiveStorage::FileNotFoundError)
52
56
  end
53
57
  end
58
+
54
59
  def delete(key)
55
60
  instrument :delete, key: key do
56
- begin
57
- client.delete_object(container, key)
58
- rescue Fog::OpenStack::Storage::NotFound
59
- false
60
- end
61
+ client.delete_object(container, key)
62
+ rescue Fog::OpenStack::Storage::NotFound
63
+ false
61
64
  end
62
65
  end
63
66
 
@@ -73,12 +76,10 @@ module ActiveStorage
73
76
 
74
77
  def exist?(key)
75
78
  instrument :exist, key: key do |payload|
76
- begin
77
- answer = object_for(key)
78
- payload[:exist] = answer.present?
79
- rescue Fog::OpenStack::Storage::NotFound
80
- payload[:exist] = false
81
- end
79
+ answer = head_for(key)
80
+ payload[:exist] = answer.present?
81
+ rescue Fog::OpenStack::Storage::NotFound
82
+ payload[:exist] = false
82
83
  end
83
84
  end
84
85
 
@@ -91,7 +92,7 @@ module ActiveStorage
91
92
  key,
92
93
  expire_at,
93
94
  filename: filename
94
- )
95
+ )
95
96
  generated_url += '&inline' if disposition.to_s != 'attachment'
96
97
  # unfortunately OpenStack Swift cannot overwrite the content type of an object via a temp url
97
98
  # so we just ignore the content_type argument here
@@ -124,18 +125,28 @@ module ActiveStorage
124
125
  }
125
126
  end
126
127
 
127
- # Non-standard method to change the content type of an existing object
128
- def change_content_type(key, content_type)
129
- client.post_object(container,
130
- key,
131
- 'Content-Type' => content_type)
132
- true
133
- rescue Fog::OpenStack::Storage::NotFound
134
- raise ActiveStorage::FileNotFoundError
128
+ def update_metadata(key, content_type:, disposition: nil, filename: nil, **)
129
+ instrument :update_metadata, key: key, content_type: content_type, disposition: disposition do
130
+ params = { 'Content-Type' => content_type }
131
+ if disposition && filename
132
+ params['Content-Disposition'] =
133
+ content_disposition_with(type: disposition, filename: ActiveStorage::Filename.wrap(filename))
134
+ end
135
+ client.post_object(container,
136
+ key,
137
+ params)
138
+ true
139
+ rescue Fog::OpenStack::Storage::NotFound
140
+ raise ActiveStorage::FileNotFoundError if defined?(ActiveStorage::FileNotFoundError)
141
+ end
135
142
  end
136
143
 
137
144
  private
138
145
 
146
+ def head_for(key)
147
+ client.head_object(container, key)
148
+ end
149
+
139
150
  def object_for(key, &block)
140
151
  client.get_object(container, key, &block)
141
152
  end
@@ -143,7 +154,7 @@ module ActiveStorage
143
154
  # ActiveStorage sends a `Digest::MD5.base64digest` checksum
144
155
  # OpenStack expects a `Digest::MD5.hexdigest` ETag
145
156
  def convert_base64digest_to_hexdigest(base64digest)
146
- base64digest.unpack('m0').first.unpack('H*').first
157
+ base64digest.unpack1('m0').unpack1('H*')
147
158
  end
148
159
 
149
160
  def unix_timestamp_expires_at(seconds_from_now)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-openstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chedli Bourguiba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "<="
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '6'
61
+ version: 5.2.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "<="
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '6'
68
+ version: 5.2.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: 1.8.11
144
144
  requirements: []
145
- rubygems_version: 3.0.3
145
+ rubygems_version: 3.1.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: ActiveStorage wrapper for OpenStack Storage