active_storage_db 0.2.0 → 1.0.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 +4 -4
- data/README.md +16 -3
- data/Rakefile +2 -1
- data/lib/active_storage/service/db_service.rb +11 -7
- data/lib/active_storage_db/version.rb +1 -1
- metadata +26 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 733afb3767f4174510cc6e59a72a5c6e137d17479fc6ec733a977ff81f80fbaf
|
4
|
+
data.tar.gz: dd7ffb266b99e6fbb2a0537b3d198a3e20200bc01dbdb43fe2407cd01161793d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ef2822294d193dd86b6bf865602ec14f13e5868a418e2ad3685d9eaade829b302659634c4effebf495f63c63a96252da50a170ad0b2e3cb831243602e0cfdcd
|
7
|
+
data.tar.gz: 8b4e73f58bfcc0f3a840812757069be9ef9859585a3a9158721ede94885d014a2b507917fdc8e5a5da7e3f17c0ef90df7146958205aa88a07243471f3b44d118
|
data/README.md
CHANGED
@@ -1,38 +1,51 @@
|
|
1
|
-
# Active Storage DB
|
1
|
+
# Active Storage DB
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/active_storage_db)
|
4
|
+
[](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml)
|
5
|
+
[](https://github.com/blocknotes/active_storage_db/actions/workflows/postgres.yml)
|
6
|
+
[](https://github.com/blocknotes/active_storage_db/actions/workflows/mysql.yml)
|
7
|
+
|
2
8
|
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database.
|
3
9
|
|
4
10
|
Main features:
|
11
|
+
- supports Rails 6.0, 6.1 and 7.0;
|
5
12
|
- all service methods implemented;
|
6
|
-
- data
|
7
|
-
- RSpec tests.
|
13
|
+
- attachment data stored in a binary field (or blob).
|
8
14
|
|
9
15
|
Useful also with platforms like Heroku (due to their ephemeral file system).
|
10
16
|
|
11
17
|
## Installation
|
18
|
+
|
12
19
|
- Setup Active Storage in your Rails application
|
13
20
|
- Add to your Gemfile `gem 'active_storage_db'` (and execute: `bundle`)
|
14
21
|
- Install the gem migrations: `bin/rails active_storage_db:install:migrations` (and execute: `bin/rails db:migrate`)
|
15
22
|
- Add to your `config/routes.rb`: `mount ActiveStorageDB::Engine => '/active_storage_db'`
|
16
23
|
- Change Active Storage service in *config/environments/development.rb* to: `config.active_storage.service = :db`
|
17
24
|
- Add to *config/storage.yml*:
|
25
|
+
|
18
26
|
```
|
19
27
|
db:
|
20
28
|
service: DB
|
21
29
|
```
|
22
30
|
|
23
31
|
## Misc
|
32
|
+
|
24
33
|
Some rake tasks are available:
|
34
|
+
|
25
35
|
- `asdb:list`: list the stored attachments
|
26
36
|
- `asdb:get`: download an attachment (ex. `bin/rails "asdb:get[ruby-logo.png,/tmp]"`)
|
27
37
|
|
28
38
|
## Do you like it? Star it!
|
39
|
+
|
29
40
|
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
30
41
|
|
31
42
|
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
|
32
43
|
|
33
44
|
## Contributors
|
45
|
+
|
34
46
|
- [Mattia Roccoberton](https://blocknot.es/): author
|
35
47
|
- Inspired by [activestorage-database-service](https://github.com/TitovDigital/activestorage-database-service) project
|
36
48
|
|
37
49
|
## License
|
50
|
+
|
38
51
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -16,7 +16,8 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
16
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
dummy_app = ENV['RAILS_7'] ? 'dummy7' : 'dummy'
|
20
|
+
APP_RAKEFILE = File.expand_path("spec/#{dummy_app}/Rakefile", __dir__)
|
20
21
|
load 'rails/tasks/engine.rake'
|
21
22
|
|
22
23
|
load 'rails/tasks/statistics.rake'
|
@@ -83,7 +83,7 @@ module ActiveStorage
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
86
|
+
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
|
87
87
|
instrument :url, key: key do |payload|
|
88
88
|
verified_token_with_expiration = ActiveStorage.verifier.generate(
|
89
89
|
{
|
@@ -95,10 +95,7 @@ module ActiveStorage
|
|
95
95
|
expires_in: expires_in,
|
96
96
|
purpose: :blob_token
|
97
97
|
)
|
98
|
-
generated_url = url_helpers.update_service_url(
|
99
|
-
verified_token_with_expiration,
|
100
|
-
host: current_host
|
101
|
-
)
|
98
|
+
generated_url = url_helpers.update_service_url(verified_token_with_expiration, host: current_host)
|
102
99
|
payload[:url] = generated_url
|
103
100
|
|
104
101
|
generated_url
|
@@ -112,7 +109,14 @@ module ActiveStorage
|
|
112
109
|
private
|
113
110
|
|
114
111
|
def current_host
|
115
|
-
ActiveStorage::Current.
|
112
|
+
if ActiveStorage::Current.respond_to? :url_options
|
113
|
+
opts = ActiveStorage::Current.url_options || {}
|
114
|
+
url = "#{opts[:protocol]}#{opts[:host]}"
|
115
|
+
url += ":#{opts[:port]}" if opts[:port]
|
116
|
+
url || ''
|
117
|
+
else
|
118
|
+
ActiveStorage::Current.host
|
119
|
+
end
|
116
120
|
end
|
117
121
|
|
118
122
|
def ensure_integrity_of(key, checksum)
|
@@ -128,7 +132,7 @@ module ActiveStorage
|
|
128
132
|
::ActiveStorageDB::File.select('OCTET_LENGTH(data) AS size').find_by(ref: key)&.size ||
|
129
133
|
raise(ActiveStorage::FileNotFoundError)
|
130
134
|
(size / @chunk_size.to_f).ceil.times.each do |i|
|
131
|
-
range = (i * @chunk_size..(i + 1) * @chunk_size - 1)
|
135
|
+
range = (i * @chunk_size..((i + 1) * @chunk_size) - 1)
|
132
136
|
yield download_chunk(key, range)
|
133
137
|
end
|
134
138
|
end
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: appraisal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.4'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: factory_bot_rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,7 +90,10 @@ files:
|
|
76
90
|
homepage: https://github.com/blocknotes/active_storage_db
|
77
91
|
licenses:
|
78
92
|
- MIT
|
79
|
-
metadata:
|
93
|
+
metadata:
|
94
|
+
homepage_uri: https://github.com/blocknotes/active_storage_db
|
95
|
+
source_code_uri: https://github.com/blocknotes/active_storage_db
|
96
|
+
rubygems_mfa_required: 'true'
|
80
97
|
post_install_message:
|
81
98
|
rdoc_options: []
|
82
99
|
require_paths:
|
@@ -85,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
102
|
requirements:
|
86
103
|
- - ">="
|
87
104
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
105
|
+
version: 2.6.0
|
89
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
107
|
requirements:
|
91
108
|
- - ">="
|
92
109
|
- !ruby/object:Gem::Version
|
93
110
|
version: '0'
|
94
111
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.1.6
|
96
113
|
signing_key:
|
97
114
|
specification_version: 4
|
98
115
|
summary: ActiveStorage DB Service
|