active_storage-send_zip 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/active_storage/send_zip.rb +22 -4
- data/lib/active_storage/send_zip/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8207888c37b524f02c443b39a3a886c570b4fe6d8a1fab0dc962ede883a24f3d
|
4
|
+
data.tar.gz: 4b960e75cdc3f948e6e77eddea418e8c6e8b07df5166d4739006569957f60d99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5558ce4b108d0a28a046f774adea7e73e15db5def44e31943ba13c28329ce2a5a35c16285e44b32beef7aa7089f0d3c518208e1cee927316195d84fb4f87f36f
|
7
|
+
data.tar.gz: 27511b5c8a954c4bf1176fc2433b005c42a0265549f649857c46de051e31a6723482e1f741f18f2b7662f0fee8ef8385ecab9f51cea360891bc66bb7d00c216a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_storage/send_zip/version'
|
2
2
|
require 'rails'
|
3
3
|
require 'zip'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'pathname'
|
4
6
|
|
5
7
|
module ActiveStorage
|
6
8
|
module SendZip
|
@@ -29,16 +31,32 @@ module ActiveStorage
|
|
29
31
|
def save_files_on_server(files)
|
30
32
|
require 'zip'
|
31
33
|
# get a temporary folder and create it
|
32
|
-
temp_folder =
|
33
|
-
|
34
|
+
temp_folder = Dir.mktmpdir 'active_storage-send_zip'
|
35
|
+
|
36
|
+
# count each files to avoid duplicates
|
37
|
+
filepaths = []
|
34
38
|
|
35
39
|
# download all ActiveStorage into
|
36
|
-
files.
|
40
|
+
files.each do |picture|
|
37
41
|
filename = picture.filename.to_s
|
38
42
|
filepath = File.join temp_folder, filename
|
43
|
+
|
44
|
+
# ensure that filename not exists
|
45
|
+
if filepaths.include? filepath
|
46
|
+
# create a new random filenames
|
47
|
+
basename = File.basename filename
|
48
|
+
extension = File.extname filename
|
49
|
+
|
50
|
+
filename = "#{basename}_#{SecureRandom.uuid}#{extension}"
|
51
|
+
filepath = File.join temp_folder, filename
|
52
|
+
end
|
53
|
+
|
39
54
|
File.open(filepath, 'wb') { |f| f.write(picture.download) }
|
40
|
-
|
55
|
+
|
56
|
+
filepaths << filepath
|
41
57
|
end
|
58
|
+
|
59
|
+
filepaths
|
42
60
|
end
|
43
61
|
|
44
62
|
# Create a temporary zip file & return the content as bytes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage-send_zip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Rousseau
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|