activestorage-openstack 1.2.0 → 1.3.0

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: e42af67ec68c44713e827b53fbd86a383c9c599b03542ff8c650f325e3a1220c
4
- data.tar.gz: 18f57c93f3a9d969fa64bb795ab7d244d5af6e5da047220fd3dc2889a0ed54e1
3
+ metadata.gz: 3390c8414d007e1749912a22a4a4f623fc294bc7f593e072f7ddd08f30539c69
4
+ data.tar.gz: a1c065e79ddecd4453a9ee22c034a43244b5438524987f107ff613ba76c52a3d
5
5
  SHA512:
6
- metadata.gz: 1e30746492e4cc1ff5e1b684c8035a29a9d5a6c671d80e603fef64bbf6e423db38757dc9b3cbef6573d1d50ff27160049901e6451095b9b69243ff203141bf21
7
- data.tar.gz: ddc2e4804076f775b9441d4ed7302fe8261c5825eab97d2e3a6b914b919f828b2fa985b49d6a09ace64ad97402ed4152204081611a131b02bc4eda0230ad60ec
6
+ metadata.gz: dbe91b3011e8b76a7ce85bc9a6d935f8ea84fffee1071e1d251e0385bde15377cb0629954fa07d6f21ea24fa6fbad9734cdefd920b552acdb7dd6317f4663426
7
+ data.tar.gz: 9d15421fabffbbaefa8b44f572af04e953201b3e56ef8082de29f7978eb866a5a85b7639ea986c3aaab8371ea43ae3c38c42333d6c4d391e79e043a2ac1dd996
@@ -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.2.0'
3
+ VERSION = '1.3.0'
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)
@@ -51,13 +55,12 @@ module ActiveStorage
51
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 = object_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,14 +125,20 @@ 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 if defined?(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.new(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
@@ -143,7 +150,7 @@ module ActiveStorage
143
150
  # ActiveStorage sends a `Digest::MD5.base64digest` checksum
144
151
  # OpenStack expects a `Digest::MD5.hexdigest` ETag
145
152
  def convert_base64digest_to_hexdigest(base64digest)
146
- base64digest.unpack('m0').first.unpack('H*').first
153
+ base64digest.unpack1('m0').unpack1('H*')
147
154
  end
148
155
 
149
156
  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.2.0
4
+ version: 1.3.0
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-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack