active_storage-send_zip 0.2.0 → 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 +8 -0
- data/Gemfile +0 -4
- data/Gemfile.lock +89 -73
- data/README.md +36 -1
- data/active_storage-send_zip.gemspec +7 -3
- data/lib/active_storage/send_zip.rb +3 -2
- data/lib/active_storage/send_zip/version.rb +3 -1
- data/lib/active_storage/send_zip_helper.rb +62 -23
- metadata +40 -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
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
0.3.4:
|
|
2
|
+
- add resize before download capability
|
|
3
|
+
0.3.2:
|
|
4
|
+
- correct rubyzip dependency
|
|
5
|
+
0.3.1:
|
|
6
|
+
- correct comportement when `ActiveStorage::Attached::Many` is given as paramter
|
|
7
|
+
0.3.0:
|
|
8
|
+
- correct subfolders creation (and break some methods signature)
|
|
1
9
|
0.2.0:
|
|
2
10
|
- move some methods to avoid to polute controller methods
|
|
3
11
|
- `ActiveStorage::SendZip#save_files_on_server` become `ActiveStorage::SendZipHelperSendZip#save_files_on_server`
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,130 +1,146 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
active_storage-send_zip (0.
|
|
4
|
+
active_storage-send_zip (0.3.4)
|
|
5
|
+
rails (> 5.2)
|
|
6
|
+
rubyzip (< 3.0)
|
|
5
7
|
|
|
6
8
|
GEM
|
|
7
9
|
remote: https://rubygems.org/
|
|
8
10
|
specs:
|
|
9
|
-
actioncable (
|
|
10
|
-
actionpack (=
|
|
11
|
+
actioncable (6.0.3.2)
|
|
12
|
+
actionpack (= 6.0.3.2)
|
|
11
13
|
nio4r (~> 2.0)
|
|
12
14
|
websocket-driver (>= 0.6.1)
|
|
13
|
-
|
|
14
|
-
actionpack (=
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
mail (>= 2.7.1)
|
|
22
|
+
actionmailer (6.0.3.2)
|
|
23
|
+
actionpack (= 6.0.3.2)
|
|
24
|
+
actionview (= 6.0.3.2)
|
|
25
|
+
activejob (= 6.0.3.2)
|
|
17
26
|
mail (~> 2.5, >= 2.5.4)
|
|
18
27
|
rails-dom-testing (~> 2.0)
|
|
19
|
-
actionpack (
|
|
20
|
-
actionview (=
|
|
21
|
-
activesupport (=
|
|
22
|
-
rack (~> 2.0)
|
|
28
|
+
actionpack (6.0.3.2)
|
|
29
|
+
actionview (= 6.0.3.2)
|
|
30
|
+
activesupport (= 6.0.3.2)
|
|
31
|
+
rack (~> 2.0, >= 2.0.8)
|
|
23
32
|
rack-test (>= 0.6.3)
|
|
24
33
|
rails-dom-testing (~> 2.0)
|
|
25
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
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
|
+
nokogiri (>= 1.8.5)
|
|
41
|
+
actionview (6.0.3.2)
|
|
42
|
+
activesupport (= 6.0.3.2)
|
|
28
43
|
builder (~> 3.1)
|
|
29
44
|
erubi (~> 1.4)
|
|
30
45
|
rails-dom-testing (~> 2.0)
|
|
31
|
-
rails-html-sanitizer (~> 1.
|
|
32
|
-
activejob (
|
|
33
|
-
activesupport (=
|
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
47
|
+
activejob (6.0.3.2)
|
|
48
|
+
activesupport (= 6.0.3.2)
|
|
34
49
|
globalid (>= 0.3.6)
|
|
35
|
-
activemodel (
|
|
36
|
-
activesupport (=
|
|
37
|
-
activerecord (
|
|
38
|
-
activemodel (=
|
|
39
|
-
activesupport (=
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
activerecord (=
|
|
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)
|
|
44
59
|
marcel (~> 0.3.1)
|
|
45
|
-
activesupport (
|
|
60
|
+
activesupport (6.0.3.2)
|
|
46
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
47
62
|
i18n (>= 0.7, < 2)
|
|
48
63
|
minitest (~> 5.1)
|
|
49
64
|
tzinfo (~> 1.1)
|
|
50
|
-
|
|
51
|
-
builder (3.2.
|
|
52
|
-
concurrent-ruby (1.1.
|
|
53
|
-
crass (1.0.
|
|
54
|
-
erubi (1.
|
|
55
|
-
globalid (0.4.
|
|
65
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
66
|
+
builder (3.2.4)
|
|
67
|
+
concurrent-ruby (1.1.6)
|
|
68
|
+
crass (1.0.6)
|
|
69
|
+
erubi (1.9.0)
|
|
70
|
+
globalid (0.4.2)
|
|
56
71
|
activesupport (>= 4.2.0)
|
|
57
|
-
i18n (1.
|
|
72
|
+
i18n (1.8.5)
|
|
58
73
|
concurrent-ruby (~> 1.0)
|
|
59
|
-
loofah (2.
|
|
74
|
+
loofah (2.6.0)
|
|
60
75
|
crass (~> 1.0.2)
|
|
61
76
|
nokogiri (>= 1.5.9)
|
|
62
77
|
mail (2.7.1)
|
|
63
78
|
mini_mime (>= 0.1.1)
|
|
64
79
|
marcel (0.3.3)
|
|
65
80
|
mimemagic (~> 0.3.2)
|
|
66
|
-
method_source (0.
|
|
67
|
-
mimemagic (0.3.
|
|
68
|
-
mini_mime (1.0.
|
|
69
|
-
mini_portile2 (2.
|
|
70
|
-
minitest (5.
|
|
71
|
-
nio4r (2.
|
|
72
|
-
nokogiri (1.
|
|
73
|
-
mini_portile2 (~> 2.
|
|
74
|
-
rack (2.
|
|
81
|
+
method_source (1.0.0)
|
|
82
|
+
mimemagic (0.3.5)
|
|
83
|
+
mini_mime (1.0.2)
|
|
84
|
+
mini_portile2 (2.4.0)
|
|
85
|
+
minitest (5.14.1)
|
|
86
|
+
nio4r (2.5.2)
|
|
87
|
+
nokogiri (1.10.10)
|
|
88
|
+
mini_portile2 (~> 2.4.0)
|
|
89
|
+
rack (2.2.3)
|
|
75
90
|
rack-test (1.1.0)
|
|
76
91
|
rack (>= 1.0, < 3)
|
|
77
|
-
rails (
|
|
78
|
-
actioncable (=
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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)
|
|
87
104
|
bundler (>= 1.3.0)
|
|
88
|
-
railties (=
|
|
105
|
+
railties (= 6.0.3.2)
|
|
89
106
|
sprockets-rails (>= 2.0.0)
|
|
90
107
|
rails-dom-testing (2.0.3)
|
|
91
108
|
activesupport (>= 4.2.0)
|
|
92
109
|
nokogiri (>= 1.6)
|
|
93
|
-
rails-html-sanitizer (1.0
|
|
94
|
-
loofah (~> 2.
|
|
95
|
-
railties (
|
|
96
|
-
actionpack (=
|
|
97
|
-
activesupport (=
|
|
110
|
+
rails-html-sanitizer (1.3.0)
|
|
111
|
+
loofah (~> 2.3)
|
|
112
|
+
railties (6.0.3.2)
|
|
113
|
+
actionpack (= 6.0.3.2)
|
|
114
|
+
activesupport (= 6.0.3.2)
|
|
98
115
|
method_source
|
|
99
116
|
rake (>= 0.8.7)
|
|
100
|
-
thor (>= 0.
|
|
101
|
-
rake (
|
|
102
|
-
rubyzip (
|
|
103
|
-
sprockets (
|
|
117
|
+
thor (>= 0.20.3, < 2.0)
|
|
118
|
+
rake (13.0.1)
|
|
119
|
+
rubyzip (2.3.0)
|
|
120
|
+
sprockets (4.0.2)
|
|
104
121
|
concurrent-ruby (~> 1.0)
|
|
105
122
|
rack (> 1, < 3)
|
|
106
123
|
sprockets-rails (3.2.1)
|
|
107
124
|
actionpack (>= 4.0)
|
|
108
125
|
activesupport (>= 4.0)
|
|
109
126
|
sprockets (>= 3.0.0)
|
|
110
|
-
thor (0.
|
|
127
|
+
thor (1.0.1)
|
|
111
128
|
thread_safe (0.3.6)
|
|
112
|
-
tzinfo (1.2.
|
|
129
|
+
tzinfo (1.2.7)
|
|
113
130
|
thread_safe (~> 0.1)
|
|
114
|
-
websocket-driver (0.7.
|
|
131
|
+
websocket-driver (0.7.3)
|
|
115
132
|
websocket-extensions (>= 0.1.0)
|
|
116
|
-
websocket-extensions (0.1.
|
|
133
|
+
websocket-extensions (0.1.5)
|
|
134
|
+
zeitwerk (2.4.0)
|
|
117
135
|
|
|
118
136
|
PLATFORMS
|
|
119
137
|
ruby
|
|
120
138
|
|
|
121
139
|
DEPENDENCIES
|
|
122
140
|
active_storage-send_zip!
|
|
123
|
-
bundler
|
|
141
|
+
bundler
|
|
124
142
|
minitest (~> 5.0)
|
|
125
|
-
|
|
126
|
-
rake (~> 10.0)
|
|
127
|
-
rubyzip (~> 1.2)
|
|
143
|
+
rake
|
|
128
144
|
|
|
129
145
|
BUNDLED WITH
|
|
130
|
-
1.
|
|
146
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -61,7 +61,10 @@ class HolidaysController < ApplicationController
|
|
|
61
61
|
def zip
|
|
62
62
|
send_zip {
|
|
63
63
|
'Holidays in Lyon <3' => Holidays.where(place: 'lyon').first.pictures,
|
|
64
|
-
'Holidays in Paris' =>
|
|
64
|
+
'Holidays in Paris' => [
|
|
65
|
+
'Eiffle Tower' => Holidays.where(place: 'eiffle_tower').first.pictures,
|
|
66
|
+
Holidays.where(place: 'paris').first.pictures
|
|
67
|
+
]
|
|
65
68
|
}
|
|
66
69
|
end
|
|
67
70
|
end
|
|
@@ -75,11 +78,43 @@ Will produce a `.zip` archive like this:
|
|
|
75
78
|
│ ├── b.png
|
|
76
79
|
│ └── c.gif
|
|
77
80
|
└── Holidays in Paris
|
|
81
|
+
├── Eiffle Tower
|
|
82
|
+
├── d.jpg
|
|
83
|
+
├── e.jpg
|
|
84
|
+
├── f.jpg
|
|
78
85
|
├── a.jpg
|
|
79
86
|
├── b.png
|
|
80
87
|
└── c.gif
|
|
81
88
|
~~~
|
|
82
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
|
+
|
|
83
118
|
## Installation
|
|
84
119
|
|
|
85
120
|
Add this line to your application's Gemfile:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
5
|
require 'active_storage/send_zip/version'
|
|
@@ -5,7 +7,7 @@ require 'active_storage/send_zip/version'
|
|
|
5
7
|
Gem::Specification.new do |spec|
|
|
6
8
|
spec.name = 'active_storage-send_zip'
|
|
7
9
|
spec.version = ActiveStorage::SendZip::VERSION
|
|
8
|
-
spec.authors = ['Alexandre Rousseau']
|
|
10
|
+
spec.authors = ['Alexandre Rousseau', 'Maxime `biximilien` Gauthier']
|
|
9
11
|
spec.email = ['contact@rousseau-alexandre.fr']
|
|
10
12
|
|
|
11
13
|
spec.summary = 'Create a zip from one or more Active Storage objects'
|
|
@@ -35,7 +37,9 @@ Gem::Specification.new do |spec|
|
|
|
35
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
36
38
|
spec.require_paths = ['lib']
|
|
37
39
|
|
|
38
|
-
spec.add_development_dependency 'bundler'
|
|
40
|
+
spec.add_development_dependency 'bundler'
|
|
39
41
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
|
40
|
-
spec.add_development_dependency 'rake'
|
|
42
|
+
spec.add_development_dependency 'rake'
|
|
43
|
+
spec.add_dependency 'rails', '> 5.2'
|
|
44
|
+
spec.add_dependency 'rubyzip', '< 3.0'
|
|
41
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)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails'
|
|
2
4
|
require 'zip'
|
|
3
5
|
require 'tempfile'
|
|
@@ -9,32 +11,60 @@ module ActiveStorage
|
|
|
9
11
|
module SendZipHelper
|
|
10
12
|
# Download active storage files on server in a temporary folder
|
|
11
13
|
#
|
|
12
|
-
# @param files [ActiveStorage::Attached::Many]
|
|
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]
|
|
16
|
+
# @return [String] folder path of saved files
|
|
17
|
+
def self.save_files_on_server(files, resize_to_limit: nil)
|
|
15
18
|
require 'zip'
|
|
16
19
|
# get a temporary folder and create it
|
|
17
20
|
temp_folder = Dir.mktmpdir 'active_storage-send_zip'
|
|
18
21
|
|
|
19
|
-
if files.is_a?
|
|
20
|
-
|
|
21
|
-
elsif files.
|
|
22
|
-
|
|
22
|
+
if files.is_a? Hash
|
|
23
|
+
filepaths = construct_with_hash(files, temp_folder)
|
|
24
|
+
elsif files.respond_to? :each
|
|
25
|
+
files.each { |file| save_file_on_server(file, temp_folder, resize_to_limit: resize_to_limit) }
|
|
26
|
+
else
|
|
27
|
+
raise ArgumentError, '`files` must be an hash or an iterable object'
|
|
28
|
+
end
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
temp_folder
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Parses hash to build out directories where folders are key names
|
|
34
|
+
#
|
|
35
|
+
# @param files [ActiveStorage::Attached::One|ActiveStorage::Attached::Many|Array|Hash] file(s) to save
|
|
36
|
+
# @return [String] folder path of saved files
|
|
37
|
+
def self.construct_with_hash(files, temp_folder)
|
|
38
|
+
filepaths = []
|
|
39
|
+
|
|
40
|
+
files.each do |subfolder, filesHash|
|
|
41
|
+
filesHash = [filesHash] unless filesHash.is_a? Array
|
|
42
|
+
|
|
43
|
+
filesHash.each do |f|
|
|
44
|
+
# Build directory strucutre recursively for hashes
|
|
45
|
+
if f.is_a? Hash
|
|
46
|
+
# Build folder for hash entry
|
|
47
|
+
folder = File.join(temp_folder, subfolder.to_s)
|
|
48
|
+
Dir.mkdir(folder) unless Dir.exist?(folder)
|
|
27
49
|
|
|
28
|
-
|
|
50
|
+
filepaths += construct_with_hash(f, folder)
|
|
51
|
+
# Save attachement
|
|
52
|
+
else
|
|
53
|
+
filepaths << save_file_on_server(f, temp_folder, subfolder: subfolder.to_s)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
29
56
|
end
|
|
57
|
+
|
|
58
|
+
filepaths
|
|
30
59
|
end
|
|
31
60
|
|
|
32
61
|
# Save the given file on the server
|
|
33
62
|
#
|
|
34
63
|
# @param file [ActiveStorage::Attached] files to save
|
|
35
64
|
# @param folder [String] where to store the file
|
|
65
|
+
# @param resize_to_limit [Array] resize to limit filter in ImageProcessing format [width, height]
|
|
36
66
|
# @return [String] the filepath of file created
|
|
37
|
-
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)
|
|
38
68
|
filename = file.filename.to_s
|
|
39
69
|
|
|
40
70
|
folder = File.join(folder, subfolder) unless subfolder.nil?
|
|
@@ -53,16 +83,26 @@ module ActiveStorage
|
|
|
53
83
|
filepath = File.join folder, filename
|
|
54
84
|
end
|
|
55
85
|
|
|
56
|
-
|
|
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
|
+
|
|
57
94
|
filepath
|
|
58
95
|
end
|
|
59
96
|
|
|
60
97
|
# Create a temporary zip file & return the content as bytes
|
|
61
98
|
#
|
|
62
|
-
# @param
|
|
99
|
+
# @param folderpath [String] folder path
|
|
63
100
|
# @return [String] as content of zip
|
|
64
|
-
def self.create_temporary_zip_file(
|
|
101
|
+
def self.create_temporary_zip_file(folderpath)
|
|
65
102
|
temp_file = Tempfile.new('user.zip')
|
|
103
|
+
folderpath_glob = File.join folderpath, '**', '*'
|
|
104
|
+
|
|
105
|
+
files = Dir.glob(folderpath_glob).reject { |e| File.directory? e }
|
|
66
106
|
|
|
67
107
|
begin
|
|
68
108
|
# Initialize the temp file as a zip file
|
|
@@ -70,19 +110,18 @@ module ActiveStorage
|
|
|
70
110
|
|
|
71
111
|
# open the zip
|
|
72
112
|
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zip|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
zip.add filename, filepath
|
|
113
|
+
files.each do |filepath|
|
|
114
|
+
filepath_zip = filepath.sub(folderpath, '').sub(File::SEPARATOR, '')
|
|
115
|
+
zip.add filepath_zip, filepath
|
|
77
116
|
end
|
|
78
117
|
end
|
|
79
118
|
|
|
80
|
-
|
|
119
|
+
File.read(temp_file.path)
|
|
81
120
|
ensure
|
|
82
121
|
# close all ressources & remove temporary files
|
|
83
|
-
temp_file.close
|
|
84
|
-
temp_file.unlink
|
|
85
|
-
|
|
122
|
+
# temp_file.close
|
|
123
|
+
# temp_file.unlink
|
|
124
|
+
# FileUtils.rm_rf(folderpath)
|
|
86
125
|
end
|
|
87
126
|
end
|
|
88
127
|
end
|
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.
|
|
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:
|
|
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,44 @@ 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
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rails
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '5.2'
|
|
63
|
+
type: :runtime
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '5.2'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rubyzip
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - "<"
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '3.0'
|
|
77
|
+
type: :runtime
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - "<"
|
|
53
82
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
83
|
+
version: '3.0'
|
|
55
84
|
description: Add a `send_zip` method in your Rails controller to send a `.zip` file
|
|
56
85
|
containing one (or many) ActiveStorage object(s)
|
|
57
86
|
email:
|
|
@@ -97,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
126
|
- !ruby/object:Gem::Version
|
|
98
127
|
version: '0'
|
|
99
128
|
requirements: []
|
|
100
|
-
|
|
101
|
-
rubygems_version: 2.7.7
|
|
129
|
+
rubygems_version: 3.0.8
|
|
102
130
|
signing_key:
|
|
103
131
|
specification_version: 4
|
|
104
132
|
summary: Create a zip from one or more Active Storage objects
|