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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7486688b7fedf6040f5c36b5fa24547bb16d9426e0e61b5a00c88bb3bf87d17
4
- data.tar.gz: 712e6d73af9d4515a367192f11bec18a0a0c7f5581a5ca0f8665503e9d95fbd6
3
+ metadata.gz: 8207888c37b524f02c443b39a3a886c570b4fe6d8a1fab0dc962ede883a24f3d
4
+ data.tar.gz: 4b960e75cdc3f948e6e77eddea418e8c6e8b07df5166d4739006569957f60d99
5
5
  SHA512:
6
- metadata.gz: 60c8312e5c80fb0663cfd396dfcbb4a72ad3e2575184ce476c27108d28b1803b7a37308d8b50618bd32787a8c780aa8fd5a5dd56554ee5ff5703f9e7099cf992
7
- data.tar.gz: 57326de525bd8cceab5005c975b89a78bc01939a8a2ee359b9591c20ff41baf9dd47e9a36ffdeadbbaa316461a366f7e7aaa7ec4b0c4a0b4ce98a07886bdd883
6
+ metadata.gz: 5558ce4b108d0a28a046f774adea7e73e15db5def44e31943ba13c28329ce2a5a35c16285e44b32beef7aa7089f0d3c518208e1cee927316195d84fb4f87f36f
7
+ data.tar.gz: 27511b5c8a954c4bf1176fc2433b005c42a0265549f649857c46de051e31a6723482e1f741f18f2b7662f0fee8ef8385ecab9f51cea360891bc66bb7d00c216a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage-send_zip (0.1.0)
4
+ active_storage-send_zip (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActiveStorage::SendZip
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/active_storage-send_zip.svg)](https://badge.fury.io/rb/active_storage-send_zip)
4
+
3
5
  Create a zip from one or more Active Storage objects and return it in a rails controller
4
6
 
5
7
  ## Installation
@@ -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 = File.join(Dir.tmpdir, 'user')
33
- FileUtils.mkdir_p(temp_folder) unless Dir.exist?(temp_folder)
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.map do |picture|
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
- filepath
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
@@ -1,5 +1,5 @@
1
1
  module ActiveStorage
2
2
  module SendZip
3
- VERSION = "0.1.0"
3
+ VERSION = '0.1.1'.freeze
4
4
  end
5
5
  end
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.0
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-30 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler