active_storage-send_zip 0.3.3 → 0.3.4
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/CHANGELOG.yml +2 -0
- data/Gemfile.lock +69 -69
- data/README.md +28 -0
- data/active_storage-send_zip.gemspec +3 -3
- data/lib/active_storage/send_zip.rb +3 -2
- data/lib/active_storage/send_zip/version.rb +1 -1
- data/lib/active_storage/send_zip_helper.rb +13 -4
- metadata +12 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 966ba7df8726b10f7eb60c06e8dcd853d83314df3f6b32864f6f664c6232bd3a
|
|
4
|
+
data.tar.gz: 4de295c7dbf7b745e25479dc14cb6ea7e0820de91af42624dcc0e2d2c9ba2032
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b33e45e395f5afefa479cb379d415186180d8c0841eaa3eb7ac37a935e982e7ef726c1b1b1c5aa7fb789b975d78403b21028a5db9c0f6b01e238bdc2f2200737
|
|
7
|
+
data.tar.gz: 0afb7ed7c8b781bde6b8673e6d5d2536e6891deb6c35959b18944d5ee2f3977ea3c39720a1de1a0c93d2311e4ee2d10ddbde0d94d2292f023ff2cecda4b1446d
|
data/CHANGELOG.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
active_storage-send_zip (0.3.
|
|
4
|
+
active_storage-send_zip (0.3.4)
|
|
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 (6.0.2
|
|
12
|
-
actionpack (= 6.0.2
|
|
11
|
+
actioncable (6.0.3.2)
|
|
12
|
+
actionpack (= 6.0.3.2)
|
|
13
13
|
nio4r (~> 2.0)
|
|
14
14
|
websocket-driver (>= 0.6.1)
|
|
15
|
-
actionmailbox (6.0.2
|
|
16
|
-
actionpack (= 6.0.2
|
|
17
|
-
activejob (= 6.0.2
|
|
18
|
-
activerecord (= 6.0.2
|
|
19
|
-
activestorage (= 6.0.2
|
|
20
|
-
activesupport (= 6.0.2
|
|
15
|
+
actionmailbox (6.0.3.2)
|
|
16
|
+
actionpack (= 6.0.3.2)
|
|
17
|
+
activejob (= 6.0.3.2)
|
|
18
|
+
activerecord (= 6.0.3.2)
|
|
19
|
+
activestorage (= 6.0.3.2)
|
|
20
|
+
activesupport (= 6.0.3.2)
|
|
21
21
|
mail (>= 2.7.1)
|
|
22
|
-
actionmailer (6.0.2
|
|
23
|
-
actionpack (= 6.0.2
|
|
24
|
-
actionview (= 6.0.2
|
|
25
|
-
activejob (= 6.0.2
|
|
22
|
+
actionmailer (6.0.3.2)
|
|
23
|
+
actionpack (= 6.0.3.2)
|
|
24
|
+
actionview (= 6.0.3.2)
|
|
25
|
+
activejob (= 6.0.3.2)
|
|
26
26
|
mail (~> 2.5, >= 2.5.4)
|
|
27
27
|
rails-dom-testing (~> 2.0)
|
|
28
|
-
actionpack (6.0.2
|
|
29
|
-
actionview (= 6.0.2
|
|
30
|
-
activesupport (= 6.0.2
|
|
28
|
+
actionpack (6.0.3.2)
|
|
29
|
+
actionview (= 6.0.3.2)
|
|
30
|
+
activesupport (= 6.0.3.2)
|
|
31
31
|
rack (~> 2.0, >= 2.0.8)
|
|
32
32
|
rack-test (>= 0.6.3)
|
|
33
33
|
rails-dom-testing (~> 2.0)
|
|
34
34
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
35
|
-
actiontext (6.0.2
|
|
36
|
-
actionpack (= 6.0.2
|
|
37
|
-
activerecord (= 6.0.2
|
|
38
|
-
activestorage (= 6.0.2
|
|
39
|
-
activesupport (= 6.0.2
|
|
35
|
+
actiontext (6.0.3.2)
|
|
36
|
+
actionpack (= 6.0.3.2)
|
|
37
|
+
activerecord (= 6.0.3.2)
|
|
38
|
+
activestorage (= 6.0.3.2)
|
|
39
|
+
activesupport (= 6.0.3.2)
|
|
40
40
|
nokogiri (>= 1.8.5)
|
|
41
|
-
actionview (6.0.2
|
|
42
|
-
activesupport (= 6.0.2
|
|
41
|
+
actionview (6.0.3.2)
|
|
42
|
+
activesupport (= 6.0.3.2)
|
|
43
43
|
builder (~> 3.1)
|
|
44
44
|
erubi (~> 1.4)
|
|
45
45
|
rails-dom-testing (~> 2.0)
|
|
46
46
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
47
|
-
activejob (6.0.2
|
|
48
|
-
activesupport (= 6.0.2
|
|
47
|
+
activejob (6.0.3.2)
|
|
48
|
+
activesupport (= 6.0.3.2)
|
|
49
49
|
globalid (>= 0.3.6)
|
|
50
|
-
activemodel (6.0.2
|
|
51
|
-
activesupport (= 6.0.2
|
|
52
|
-
activerecord (6.0.2
|
|
53
|
-
activemodel (= 6.0.2
|
|
54
|
-
activesupport (= 6.0.2
|
|
55
|
-
activestorage (6.0.2
|
|
56
|
-
actionpack (= 6.0.2
|
|
57
|
-
activejob (= 6.0.2
|
|
58
|
-
activerecord (= 6.0.2
|
|
50
|
+
activemodel (6.0.3.2)
|
|
51
|
+
activesupport (= 6.0.3.2)
|
|
52
|
+
activerecord (6.0.3.2)
|
|
53
|
+
activemodel (= 6.0.3.2)
|
|
54
|
+
activesupport (= 6.0.3.2)
|
|
55
|
+
activestorage (6.0.3.2)
|
|
56
|
+
actionpack (= 6.0.3.2)
|
|
57
|
+
activejob (= 6.0.3.2)
|
|
58
|
+
activerecord (= 6.0.3.2)
|
|
59
59
|
marcel (~> 0.3.1)
|
|
60
|
-
activesupport (6.0.2
|
|
60
|
+
activesupport (6.0.3.2)
|
|
61
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
62
62
|
i18n (>= 0.7, < 2)
|
|
63
63
|
minitest (~> 5.1)
|
|
64
64
|
tzinfo (~> 1.1)
|
|
65
|
-
zeitwerk (~> 2.2)
|
|
65
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
66
66
|
builder (3.2.4)
|
|
67
67
|
concurrent-ruby (1.1.6)
|
|
68
68
|
crass (1.0.6)
|
|
69
69
|
erubi (1.9.0)
|
|
70
70
|
globalid (0.4.2)
|
|
71
71
|
activesupport (>= 4.2.0)
|
|
72
|
-
i18n (1.8.
|
|
72
|
+
i18n (1.8.5)
|
|
73
73
|
concurrent-ruby (~> 1.0)
|
|
74
|
-
loofah (2.
|
|
74
|
+
loofah (2.6.0)
|
|
75
75
|
crass (~> 1.0.2)
|
|
76
76
|
nokogiri (>= 1.5.9)
|
|
77
77
|
mail (2.7.1)
|
|
78
78
|
mini_mime (>= 0.1.1)
|
|
79
79
|
marcel (0.3.3)
|
|
80
80
|
mimemagic (~> 0.3.2)
|
|
81
|
-
method_source (0.
|
|
82
|
-
mimemagic (0.3.
|
|
81
|
+
method_source (1.0.0)
|
|
82
|
+
mimemagic (0.3.5)
|
|
83
83
|
mini_mime (1.0.2)
|
|
84
84
|
mini_portile2 (2.4.0)
|
|
85
|
-
minitest (5.14.
|
|
85
|
+
minitest (5.14.1)
|
|
86
86
|
nio4r (2.5.2)
|
|
87
|
-
nokogiri (1.10.
|
|
87
|
+
nokogiri (1.10.10)
|
|
88
88
|
mini_portile2 (~> 2.4.0)
|
|
89
|
-
rack (2.2.
|
|
89
|
+
rack (2.2.3)
|
|
90
90
|
rack-test (1.1.0)
|
|
91
91
|
rack (>= 1.0, < 3)
|
|
92
|
-
rails (6.0.2
|
|
93
|
-
actioncable (= 6.0.2
|
|
94
|
-
actionmailbox (= 6.0.2
|
|
95
|
-
actionmailer (= 6.0.2
|
|
96
|
-
actionpack (= 6.0.2
|
|
97
|
-
actiontext (= 6.0.2
|
|
98
|
-
actionview (= 6.0.2
|
|
99
|
-
activejob (= 6.0.2
|
|
100
|
-
activemodel (= 6.0.2
|
|
101
|
-
activerecord (= 6.0.2
|
|
102
|
-
activestorage (= 6.0.2
|
|
103
|
-
activesupport (= 6.0.2
|
|
92
|
+
rails (6.0.3.2)
|
|
93
|
+
actioncable (= 6.0.3.2)
|
|
94
|
+
actionmailbox (= 6.0.3.2)
|
|
95
|
+
actionmailer (= 6.0.3.2)
|
|
96
|
+
actionpack (= 6.0.3.2)
|
|
97
|
+
actiontext (= 6.0.3.2)
|
|
98
|
+
actionview (= 6.0.3.2)
|
|
99
|
+
activejob (= 6.0.3.2)
|
|
100
|
+
activemodel (= 6.0.3.2)
|
|
101
|
+
activerecord (= 6.0.3.2)
|
|
102
|
+
activestorage (= 6.0.3.2)
|
|
103
|
+
activesupport (= 6.0.3.2)
|
|
104
104
|
bundler (>= 1.3.0)
|
|
105
|
-
railties (= 6.0.2
|
|
105
|
+
railties (= 6.0.3.2)
|
|
106
106
|
sprockets-rails (>= 2.0.0)
|
|
107
107
|
rails-dom-testing (2.0.3)
|
|
108
108
|
activesupport (>= 4.2.0)
|
|
109
109
|
nokogiri (>= 1.6)
|
|
110
110
|
rails-html-sanitizer (1.3.0)
|
|
111
111
|
loofah (~> 2.3)
|
|
112
|
-
railties (6.0.2
|
|
113
|
-
actionpack (= 6.0.2
|
|
114
|
-
activesupport (= 6.0.2
|
|
112
|
+
railties (6.0.3.2)
|
|
113
|
+
actionpack (= 6.0.3.2)
|
|
114
|
+
activesupport (= 6.0.3.2)
|
|
115
115
|
method_source
|
|
116
116
|
rake (>= 0.8.7)
|
|
117
117
|
thor (>= 0.20.3, < 2.0)
|
|
118
|
-
rake (
|
|
119
|
-
rubyzip (2.
|
|
120
|
-
sprockets (4.0.
|
|
118
|
+
rake (13.0.1)
|
|
119
|
+
rubyzip (2.3.0)
|
|
120
|
+
sprockets (4.0.2)
|
|
121
121
|
concurrent-ruby (~> 1.0)
|
|
122
122
|
rack (> 1, < 3)
|
|
123
123
|
sprockets-rails (3.2.1)
|
|
@@ -126,21 +126,21 @@ GEM
|
|
|
126
126
|
sprockets (>= 3.0.0)
|
|
127
127
|
thor (1.0.1)
|
|
128
128
|
thread_safe (0.3.6)
|
|
129
|
-
tzinfo (1.2.
|
|
129
|
+
tzinfo (1.2.7)
|
|
130
130
|
thread_safe (~> 0.1)
|
|
131
|
-
websocket-driver (0.7.
|
|
131
|
+
websocket-driver (0.7.3)
|
|
132
132
|
websocket-extensions (>= 0.1.0)
|
|
133
|
-
websocket-extensions (0.1.
|
|
134
|
-
zeitwerk (2.
|
|
133
|
+
websocket-extensions (0.1.5)
|
|
134
|
+
zeitwerk (2.4.0)
|
|
135
135
|
|
|
136
136
|
PLATFORMS
|
|
137
137
|
ruby
|
|
138
138
|
|
|
139
139
|
DEPENDENCIES
|
|
140
140
|
active_storage-send_zip!
|
|
141
|
-
bundler
|
|
141
|
+
bundler
|
|
142
142
|
minitest (~> 5.0)
|
|
143
|
-
rake
|
|
143
|
+
rake
|
|
144
144
|
|
|
145
145
|
BUNDLED WITH
|
|
146
|
-
1.
|
|
146
|
+
2.1.4
|
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.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandre Rousseau
|
|
8
|
+
- Maxime `biximilien` Gauthier
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: exe
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
12
|
+
date: 2020-07-30 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
|
|
@@ -125,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
125
126
|
- !ruby/object:Gem::Version
|
|
126
127
|
version: '0'
|
|
127
128
|
requirements: []
|
|
128
|
-
|
|
129
|
-
rubygems_version: 2.7.8
|
|
129
|
+
rubygems_version: 3.0.8
|
|
130
130
|
signing_key:
|
|
131
131
|
specification_version: 4
|
|
132
132
|
summary: Create a zip from one or more Active Storage objects
|