activestorage_database 1.0 → 2.1

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: 0c09c92d2e2f7584a58c68836d5f6a946ec84ec0482b071fe6c1db4d3107bae9
4
- data.tar.gz: fc7202ce7879b163a75fb0719c12e2de79d53deb79afca1d13c67a24edc28307
3
+ metadata.gz: 41730c0975c58c903b03a756fa67ebaec9ae373acdd58430346fdf98f74194f0
4
+ data.tar.gz: dbfc0d6d79f743e320fe244bfa6d9e5441bdd5b9435b6eb138cc7898e7b8b0c8
5
5
  SHA512:
6
- metadata.gz: 171507085f3e4db49773b71c72e79e0b8e9c4160fb3085fd70546bc914597b8e9c059d9fe3568a651ef7e0a63770762ff777b4b30064d112bdd3a77cc69116eb
7
- data.tar.gz: 405ada0a3112021aa408f46fda10aa610ccb7381b3feab730072ce370470dca545dd3239a88e92e3616de06830a0dfa8a4e0f3da27d07046d44dfbb527cd131e
6
+ metadata.gz: 6f8de2aa772e7123e38dc63718aac06de33883565ce4e077e33344eb6ee7d303ee42d6f9b880b1497fd48d974fe913be7cd71d8fda901b5469c0dfd024720859
7
+ data.tar.gz: 1c82f1b1c0dbb6d900a6c76762e55ed869804e909b8d85824fb515f7fd47283c64eda1dc77d45e627b1b7c7682cfd6c9e7842c6898c484b2199ac6e64dcda469
data/README.md CHANGED
@@ -11,6 +11,15 @@ access to these public services.
11
11
  This project is aimed more for those type of apps, if you store TBs of files then you should probabbly look into other solutions.
12
12
 
13
13
 
14
+ ## Compatibility
15
+
16
+ Rails Version | ActiveStorageBase64 Version
17
+ --------------|-----------------------------
18
+ 7 | 2.x
19
+ 6 | 1.x
20
+
21
+
22
+
14
23
  # How it works
15
24
 
16
25
  Every file is stored inside the `activestorage_database_files` table as a `binary/bytea`.
@@ -62,3 +71,9 @@ After the setup you can work with ActiveStorge API as if it was any other `Activ
62
71
 
63
72
  ## License
64
73
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+
75
+ ## Credits
76
+
77
+ Active Storage Database is maintained by [WizardHealth](https://www.wizardhealth.co/?lang=en).
78
+
79
+ [<img src="https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png" width="100"/>](http://www.rootstrap.com)
@@ -28,28 +28,30 @@ class ActivestorageDatabase::FilesController < ActiveStorage::BaseController
28
28
  end
29
29
 
30
30
  private
31
- def database_service
32
- ActiveStorage::Blob.service
33
- end
34
31
 
35
- def decode_verified_key
36
- ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
37
- end
32
+ def database_service
33
+ ActiveStorage::Blob.service
34
+ end
38
35
 
39
- def decode_verified_token
40
- ActiveStorage.verifier.verified(params[:encoded_token], purpose: :blob_token)
41
- end
36
+ def decode_verified_key
37
+ key = ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
38
+ key&.deep_symbolize_keys
39
+ end
42
40
 
43
- def serve_file(key, content_type:, disposition:)
44
- options = {
45
- type: content_type || DEFAULT_SEND_FILE_TYPE,
46
- disposition: disposition || DEFAULT_SEND_FILE_DISPOSITION
47
- }
41
+ def decode_verified_token
42
+ ActiveStorage.verifier.verified(params[:encoded_token], purpose: :blob_token)
43
+ end
48
44
 
49
- send_data database_service.download(key), options
50
- end
45
+ def serve_file(key, content_type:, disposition:)
46
+ options = {
47
+ type: content_type || DEFAULT_SEND_FILE_TYPE,
48
+ disposition: disposition || DEFAULT_SEND_FILE_DISPOSITION
49
+ }
51
50
 
52
- def acceptable_content?(token)
53
- token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length
54
- end
51
+ send_data database_service.download(key), options
52
+ end
53
+
54
+ def acceptable_content?(token)
55
+ token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length
56
+ end
55
57
  end
@@ -4,7 +4,7 @@ module ActiveStorage
4
4
  class Service::DatabaseService < Service
5
5
  CHUNK_SIZE = 1.megabytes.freeze
6
6
 
7
- def upload(key, io, checksum: nil, **options)
7
+ def upload(key, io, checksum: nil, **)
8
8
  instrument :upload, key: key, checksum: checksum do
9
9
  file = ActivestorageDatabase::File.create!(key: key, data: io.read)
10
10
  ensure_integrity_of(key, checksum) if checksum
@@ -65,19 +65,8 @@ module ActiveStorage
65
65
  expires_in: expires_in,
66
66
  purpose: :blob_key
67
67
  )
68
- current_uri = URI.parse(current_host)
69
- generated_url = url_helpers.service_url(
70
- verified_key_with_expiration,
71
- protocol: current_uri.scheme,
72
- host: current_uri.host,
73
- port: current_uri.port,
74
- disposition: content_disposition,
75
- content_type: content_type,
76
- filename: filename
77
- )
78
- payload[:url] = generated_url
79
68
 
80
- generated_url
69
+ url_helpers.service_url(verified_key_with_expiration, filename: filename, **url_options)
81
70
  end
82
71
  end
83
72
 
@@ -93,13 +82,10 @@ module ActiveStorage
93
82
  expires_in: expires_in,
94
83
  purpose: :blob_token
95
84
  )
96
- generated_url = url_helpers.update_service_url(
97
- verified_token_with_expiration,
98
- host: current_host
99
- )
100
- payload[:url] = generated_url
101
85
 
102
- generated_url
86
+ url_helpers.update_service_url(verified_token_with_expiration, url_options) do |generated_url|
87
+ payload[:url] = generated_url
88
+ end
103
89
  end
104
90
  end
105
91
 
@@ -108,11 +94,10 @@ module ActiveStorage
108
94
  end
109
95
 
110
96
  private
111
- def current_host
112
- ActiveStorage::Current.host
97
+ def url_options
98
+ ActiveStorage::Current.url_options
113
99
  end
114
100
 
115
-
116
101
  def ensure_integrity_of(key, checksum)
117
102
  file = ::ActivestorageDatabase::File.find_by(key: key)
118
103
  return if Digest::MD5.base64digest(file.data) == checksum
@@ -1,3 +1,3 @@
1
1
  module ActivestorageDatabase
2
- VERSION = "1.0"
2
+ VERSION = "2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage_database
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '2.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Maric
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-18 00:00:00.000000000 Z
12
+ date: 2024-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 6.0.0
20
+ version: '7.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 6.0.0
27
+ version: '7.0'
28
28
  description: Store ActiveStorage attachments inside the database.
29
29
  email:
30
30
  - dinom@hey.com
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.2.22
69
+ rubygems_version: 3.4.1
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Store ActiveStorage attachments inside the database.