active_storage-send_zip 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.yml +2 -0
- data/Gemfile.lock +162 -111
- data/README.md +28 -0
- data/active_storage-send_zip.gemspec +3 -3
- data/lib/active_storage/send_zip/version.rb +1 -1
- data/lib/active_storage/send_zip.rb +3 -2
- data/lib/active_storage/send_zip_helper.rb +13 -4
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4a1c89a7b8a630d378b77f1e0cadd4ddb7eaadaa96f4040875ed4cc41944775
|
4
|
+
data.tar.gz: b366d585f90a600c4210053c52a1c69e13d7cd226574ad3f6b3400c6d37729f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9f936395e0bbb982b150b79a513d91f8703238ec3b70d7f95a0c7c00d417696dc45a32366294e42f2b26de6c5bc67628dd67ac7e42fd9cb0d96b1382459144a
|
7
|
+
data.tar.gz: 4a9087b99c8bb4116af9b2ea553a58091827a4c4fbc1a305f378e573f89d64b2d0180a1d7eed664ea193f19cd0ec41c3ffb610878e9d9b2a017a96a5658372c7
|
data/CHANGELOG.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,146 +1,197 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_storage-send_zip (0.3.
|
4
|
+
active_storage-send_zip (0.3.5)
|
5
5
|
rails (> 5.2)
|
6
6
|
rubyzip (< 3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (
|
12
|
-
actionpack (=
|
11
|
+
actioncable (7.1.3.2)
|
12
|
+
actionpack (= 7.1.3.2)
|
13
|
+
activesupport (= 7.1.3.2)
|
13
14
|
nio4r (~> 2.0)
|
14
15
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
zeitwerk (~> 2.6)
|
17
|
+
actionmailbox (7.1.3.2)
|
18
|
+
actionpack (= 7.1.3.2)
|
19
|
+
activejob (= 7.1.3.2)
|
20
|
+
activerecord (= 7.1.3.2)
|
21
|
+
activestorage (= 7.1.3.2)
|
22
|
+
activesupport (= 7.1.3.2)
|
21
23
|
mail (>= 2.7.1)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
net-imap
|
25
|
+
net-pop
|
26
|
+
net-smtp
|
27
|
+
actionmailer (7.1.3.2)
|
28
|
+
actionpack (= 7.1.3.2)
|
29
|
+
actionview (= 7.1.3.2)
|
30
|
+
activejob (= 7.1.3.2)
|
31
|
+
activesupport (= 7.1.3.2)
|
26
32
|
mail (~> 2.5, >= 2.5.4)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
net-imap
|
34
|
+
net-pop
|
35
|
+
net-smtp
|
36
|
+
rails-dom-testing (~> 2.2)
|
37
|
+
actionpack (7.1.3.2)
|
38
|
+
actionview (= 7.1.3.2)
|
39
|
+
activesupport (= 7.1.3.2)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
racc
|
42
|
+
rack (>= 2.2.4)
|
43
|
+
rack-session (>= 1.0.1)
|
32
44
|
rack-test (>= 0.6.3)
|
33
|
-
rails-dom-testing (~> 2.
|
34
|
-
rails-html-sanitizer (~> 1.
|
35
|
-
actiontext (
|
36
|
-
actionpack (=
|
37
|
-
activerecord (=
|
38
|
-
activestorage (=
|
39
|
-
activesupport (=
|
45
|
+
rails-dom-testing (~> 2.2)
|
46
|
+
rails-html-sanitizer (~> 1.6)
|
47
|
+
actiontext (7.1.3.2)
|
48
|
+
actionpack (= 7.1.3.2)
|
49
|
+
activerecord (= 7.1.3.2)
|
50
|
+
activestorage (= 7.1.3.2)
|
51
|
+
activesupport (= 7.1.3.2)
|
52
|
+
globalid (>= 0.6.0)
|
40
53
|
nokogiri (>= 1.8.5)
|
41
|
-
actionview (
|
42
|
-
activesupport (=
|
54
|
+
actionview (7.1.3.2)
|
55
|
+
activesupport (= 7.1.3.2)
|
43
56
|
builder (~> 3.1)
|
44
|
-
erubi (~> 1.
|
45
|
-
rails-dom-testing (~> 2.
|
46
|
-
rails-html-sanitizer (~> 1.
|
47
|
-
activejob (
|
48
|
-
activesupport (=
|
57
|
+
erubi (~> 1.11)
|
58
|
+
rails-dom-testing (~> 2.2)
|
59
|
+
rails-html-sanitizer (~> 1.6)
|
60
|
+
activejob (7.1.3.2)
|
61
|
+
activesupport (= 7.1.3.2)
|
49
62
|
globalid (>= 0.3.6)
|
50
|
-
activemodel (
|
51
|
-
activesupport (=
|
52
|
-
activerecord (
|
53
|
-
activemodel (=
|
54
|
-
activesupport (=
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
activemodel (7.1.3.2)
|
64
|
+
activesupport (= 7.1.3.2)
|
65
|
+
activerecord (7.1.3.2)
|
66
|
+
activemodel (= 7.1.3.2)
|
67
|
+
activesupport (= 7.1.3.2)
|
68
|
+
timeout (>= 0.4.0)
|
69
|
+
activestorage (7.1.3.2)
|
70
|
+
actionpack (= 7.1.3.2)
|
71
|
+
activejob (= 7.1.3.2)
|
72
|
+
activerecord (= 7.1.3.2)
|
73
|
+
activesupport (= 7.1.3.2)
|
74
|
+
marcel (~> 1.0)
|
75
|
+
activesupport (7.1.3.2)
|
76
|
+
base64
|
77
|
+
bigdecimal
|
61
78
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
79
|
+
connection_pool (>= 2.2.5)
|
80
|
+
drb
|
81
|
+
i18n (>= 1.6, < 2)
|
82
|
+
minitest (>= 5.1)
|
83
|
+
mutex_m
|
84
|
+
tzinfo (~> 2.0)
|
85
|
+
base64 (0.2.0)
|
86
|
+
bigdecimal (3.1.6)
|
66
87
|
builder (3.2.4)
|
67
|
-
concurrent-ruby (1.
|
88
|
+
concurrent-ruby (1.2.3)
|
89
|
+
connection_pool (2.4.1)
|
68
90
|
crass (1.0.6)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
91
|
+
date (3.3.4)
|
92
|
+
drb (2.2.0)
|
93
|
+
ruby2_keywords
|
94
|
+
erubi (1.12.0)
|
95
|
+
globalid (1.2.1)
|
96
|
+
activesupport (>= 6.1)
|
97
|
+
i18n (1.14.1)
|
73
98
|
concurrent-ruby (~> 1.0)
|
74
|
-
|
99
|
+
io-console (0.7.2)
|
100
|
+
irb (1.11.2)
|
101
|
+
rdoc
|
102
|
+
reline (>= 0.4.2)
|
103
|
+
loofah (2.22.0)
|
75
104
|
crass (~> 1.0.2)
|
76
|
-
nokogiri (>= 1.
|
77
|
-
mail (2.
|
105
|
+
nokogiri (>= 1.12.0)
|
106
|
+
mail (2.8.1)
|
78
107
|
mini_mime (>= 0.1.1)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
mini_mime (1.
|
84
|
-
mini_portile2 (2.
|
85
|
-
minitest (5.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
net-imap
|
109
|
+
net-pop
|
110
|
+
net-smtp
|
111
|
+
marcel (1.0.2)
|
112
|
+
mini_mime (1.1.5)
|
113
|
+
mini_portile2 (2.8.5)
|
114
|
+
minitest (5.22.2)
|
115
|
+
mutex_m (0.2.0)
|
116
|
+
net-imap (0.4.10)
|
117
|
+
date
|
118
|
+
net-protocol
|
119
|
+
net-pop (0.1.2)
|
120
|
+
net-protocol
|
121
|
+
net-protocol (0.2.2)
|
122
|
+
timeout
|
123
|
+
net-smtp (0.4.0.1)
|
124
|
+
net-protocol
|
125
|
+
nio4r (2.7.0)
|
126
|
+
nokogiri (1.15.5)
|
127
|
+
mini_portile2 (~> 2.8.2)
|
128
|
+
racc (~> 1.4)
|
129
|
+
psych (5.1.2)
|
130
|
+
stringio
|
131
|
+
racc (1.7.3)
|
132
|
+
rack (3.0.9.1)
|
133
|
+
rack-session (2.0.0)
|
134
|
+
rack (>= 3.0.0)
|
135
|
+
rack-test (2.1.0)
|
136
|
+
rack (>= 1.3)
|
137
|
+
rackup (2.1.0)
|
138
|
+
rack (>= 3)
|
139
|
+
webrick (~> 1.8)
|
140
|
+
rails (7.1.3.2)
|
141
|
+
actioncable (= 7.1.3.2)
|
142
|
+
actionmailbox (= 7.1.3.2)
|
143
|
+
actionmailer (= 7.1.3.2)
|
144
|
+
actionpack (= 7.1.3.2)
|
145
|
+
actiontext (= 7.1.3.2)
|
146
|
+
actionview (= 7.1.3.2)
|
147
|
+
activejob (= 7.1.3.2)
|
148
|
+
activemodel (= 7.1.3.2)
|
149
|
+
activerecord (= 7.1.3.2)
|
150
|
+
activestorage (= 7.1.3.2)
|
151
|
+
activesupport (= 7.1.3.2)
|
152
|
+
bundler (>= 1.15.0)
|
153
|
+
railties (= 7.1.3.2)
|
154
|
+
rails-dom-testing (2.2.0)
|
155
|
+
activesupport (>= 5.0.0)
|
156
|
+
minitest
|
109
157
|
nokogiri (>= 1.6)
|
110
|
-
rails-html-sanitizer (1.
|
111
|
-
loofah (~> 2.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
158
|
+
rails-html-sanitizer (1.6.0)
|
159
|
+
loofah (~> 2.21)
|
160
|
+
nokogiri (~> 1.14)
|
161
|
+
railties (7.1.3.2)
|
162
|
+
actionpack (= 7.1.3.2)
|
163
|
+
activesupport (= 7.1.3.2)
|
164
|
+
irb
|
165
|
+
rackup (>= 1.0.0)
|
166
|
+
rake (>= 12.2)
|
167
|
+
thor (~> 1.0, >= 1.2.2)
|
168
|
+
zeitwerk (~> 2.6)
|
169
|
+
rake (13.1.0)
|
170
|
+
rdoc (6.6.2)
|
171
|
+
psych (>= 4.0.0)
|
172
|
+
reline (0.4.3)
|
173
|
+
io-console (~> 0.5)
|
174
|
+
ruby2_keywords (0.0.5)
|
175
|
+
rubyzip (2.3.2)
|
176
|
+
stringio (3.1.0)
|
177
|
+
thor (1.3.1)
|
178
|
+
timeout (0.4.1)
|
179
|
+
tzinfo (2.0.6)
|
121
180
|
concurrent-ruby (~> 1.0)
|
122
|
-
|
123
|
-
|
124
|
-
actionpack (>= 4.0)
|
125
|
-
activesupport (>= 4.0)
|
126
|
-
sprockets (>= 3.0.0)
|
127
|
-
thor (1.0.1)
|
128
|
-
thread_safe (0.3.6)
|
129
|
-
tzinfo (1.2.6)
|
130
|
-
thread_safe (~> 0.1)
|
131
|
-
websocket-driver (0.7.1)
|
181
|
+
webrick (1.8.1)
|
182
|
+
websocket-driver (0.7.6)
|
132
183
|
websocket-extensions (>= 0.1.0)
|
133
|
-
websocket-extensions (0.1.
|
134
|
-
zeitwerk (2.
|
184
|
+
websocket-extensions (0.1.5)
|
185
|
+
zeitwerk (2.6.13)
|
135
186
|
|
136
187
|
PLATFORMS
|
137
188
|
ruby
|
138
189
|
|
139
190
|
DEPENDENCIES
|
140
191
|
active_storage-send_zip!
|
141
|
-
bundler
|
192
|
+
bundler
|
142
193
|
minitest (~> 5.0)
|
143
|
-
rake
|
194
|
+
rake
|
144
195
|
|
145
196
|
BUNDLED WITH
|
146
|
-
|
197
|
+
2.4.1
|
data/README.md
CHANGED
@@ -87,6 +87,34 @@ Will produce a `.zip` archive like this:
|
|
87
87
|
└── c.gif
|
88
88
|
~~~
|
89
89
|
|
90
|
+
|
91
|
+
### Resize images before downloading
|
92
|
+
|
93
|
+
You can resize the images before zipping and downloading them :
|
94
|
+
|
95
|
+
~~~ruby
|
96
|
+
# app/controllers/galleries_controller.rb
|
97
|
+
class GalleriesController < ApplicationController
|
98
|
+
include ActiveStorage::SendZip
|
99
|
+
|
100
|
+
# ...
|
101
|
+
|
102
|
+
# GET /galleries/1/download
|
103
|
+
def download
|
104
|
+
respond_to do |format|
|
105
|
+
if params[:format] == 'web_size'
|
106
|
+
format.zip { send_zip @gallery.photos, resize_to_limit: [1920, 1080] }
|
107
|
+
elsif params[:format] == 'tiny'
|
108
|
+
format.zip { send_zip @gallery.photos, resize_to_limit: [480, 270] }
|
109
|
+
else
|
110
|
+
format.zip { send_zip @gallery.photos }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
~~~
|
116
|
+
|
117
|
+
|
90
118
|
## Installation
|
91
119
|
|
92
120
|
Add this line to your application's Gemfile:
|
@@ -7,7 +7,7 @@ require 'active_storage/send_zip/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'active_storage-send_zip'
|
9
9
|
spec.version = ActiveStorage::SendZip::VERSION
|
10
|
-
spec.authors = ['Alexandre Rousseau']
|
10
|
+
spec.authors = ['Alexandre Rousseau', 'Maxime `biximilien` Gauthier']
|
11
11
|
spec.email = ['contact@rousseau-alexandre.fr']
|
12
12
|
|
13
13
|
spec.summary = 'Create a zip from one or more Active Storage objects'
|
@@ -37,9 +37,9 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
|
40
|
-
spec.add_development_dependency 'bundler'
|
40
|
+
spec.add_development_dependency 'bundler'
|
41
41
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
42
|
-
spec.add_development_dependency 'rake'
|
42
|
+
spec.add_development_dependency 'rake'
|
43
43
|
spec.add_dependency 'rails', '> 5.2'
|
44
44
|
spec.add_dependency 'rubyzip', '< 3.0'
|
45
45
|
end
|
@@ -14,9 +14,10 @@ module ActiveStorage
|
|
14
14
|
#
|
15
15
|
# @param active_storages [ActiveStorage::Attached::Many] files to save
|
16
16
|
# @param filename [ActiveStorage::Attached::Many] files to save
|
17
|
-
|
17
|
+
# @param resize_to_limit [Array] resize to limit filter in ImageProcessing format [width, height]
|
18
|
+
def send_zip(active_storages, filename: 'my.zip', resize_to_limit: nil)
|
18
19
|
require 'zip'
|
19
|
-
files = SendZipHelper.save_files_on_server active_storages
|
20
|
+
files = SendZipHelper.save_files_on_server active_storages, resize_to_limit: resize_to_limit
|
20
21
|
zip_data = SendZipHelper.create_temporary_zip_file files
|
21
22
|
|
22
23
|
send_data(zip_data, type: 'application/zip', filename: filename)
|
@@ -12,8 +12,9 @@ module ActiveStorage
|
|
12
12
|
# Download active storage files on server in a temporary folder
|
13
13
|
#
|
14
14
|
# @param files [ActiveStorage::Attached::One|ActiveStorage::Attached::Many|Array|Hash] file(s) to save
|
15
|
+
# @param resize_to_limit [Array] resize to limit filter in ImageProcessing format [width, height]
|
15
16
|
# @return [String] folder path of saved files
|
16
|
-
def self.save_files_on_server(files)
|
17
|
+
def self.save_files_on_server(files, resize_to_limit: nil)
|
17
18
|
require 'zip'
|
18
19
|
# get a temporary folder and create it
|
19
20
|
temp_folder = Dir.mktmpdir 'active_storage-send_zip'
|
@@ -21,7 +22,7 @@ module ActiveStorage
|
|
21
22
|
if files.is_a? Hash
|
22
23
|
filepaths = construct_with_hash(files, temp_folder)
|
23
24
|
elsif files.respond_to? :each
|
24
|
-
files.each { |file| save_file_on_server(file, temp_folder) }
|
25
|
+
files.each { |file| save_file_on_server(file, temp_folder, resize_to_limit: resize_to_limit) }
|
25
26
|
else
|
26
27
|
raise ArgumentError, '`files` must be an hash or an iterable object'
|
27
28
|
end
|
@@ -61,8 +62,9 @@ module ActiveStorage
|
|
61
62
|
#
|
62
63
|
# @param file [ActiveStorage::Attached] files to save
|
63
64
|
# @param folder [String] where to store the file
|
65
|
+
# @param resize_to_limit [Array] resize to limit filter in ImageProcessing format [width, height]
|
64
66
|
# @return [String] the filepath of file created
|
65
|
-
def self.save_file_on_server(file, folder, subfolder: nil)
|
67
|
+
def self.save_file_on_server(file, folder, subfolder: nil, resize_to_limit: nil)
|
66
68
|
filename = file.filename.to_s
|
67
69
|
|
68
70
|
folder = File.join(folder, subfolder) unless subfolder.nil?
|
@@ -81,7 +83,14 @@ module ActiveStorage
|
|
81
83
|
filepath = File.join folder, filename
|
82
84
|
end
|
83
85
|
|
84
|
-
|
86
|
+
# resize images if needed
|
87
|
+
unless resize_to_limit.nil?
|
88
|
+
file = file.variant(resize_to_limit: resize_to_limit).processed
|
89
|
+
end
|
90
|
+
|
91
|
+
# write the file on disk
|
92
|
+
File.open(filepath, 'wb') { |f| f.write(file.service.download(file.key)) }
|
93
|
+
|
85
94
|
filepath
|
86
95
|
end
|
87
96
|
|
metadata
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage-send_zip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Rousseau
|
8
|
-
|
8
|
+
- Maxime `biximilien` Gauthier
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '0'
|
20
21
|
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- - "
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: minitest
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +43,16 @@ dependencies:
|
|
42
43
|
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rails
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +111,7 @@ metadata:
|
|
110
111
|
allowed_push_host: https://rubygems.org/
|
111
112
|
homepage_uri: https://github.com/madeindjs/active_storage-send_zip
|
112
113
|
source_code_uri: https://github.com/madeindjs/active_storage-send_zip
|
113
|
-
post_install_message:
|
114
|
+
post_install_message:
|
114
115
|
rdoc_options: []
|
115
116
|
require_paths:
|
116
117
|
- lib
|
@@ -125,9 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
- !ruby/object:Gem::Version
|
126
127
|
version: '0'
|
127
128
|
requirements: []
|
128
|
-
|
129
|
-
|
130
|
-
signing_key:
|
129
|
+
rubygems_version: 3.4.20
|
130
|
+
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Create a zip from one or more Active Storage objects
|
133
133
|
test_files: []
|