balloon 1.1.1 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 909d8652d1b69823ed4a0a65e8802e5adf41fe37183111ad6d0f9e4035e7e882
4
- data.tar.gz: 23e566f565e83f05d92740761ad7b9d1c6b851e73e038d23d9cac833ae09f483
3
+ metadata.gz: 93ee09077783f74ff932ed5552a56e6bfff56c32761cfe9e3a56c71e29a3420f
4
+ data.tar.gz: b3a4618315f7344436e4338f37080409f7c1664535d8e3a060688105eb9286e1
5
5
  SHA512:
6
- metadata.gz: 99174822071a213f398c7fcec40c40f232852dce889f095241df9a7225099040cef5834104b878a1a41398231fad1624b29e286ca5b8063f5629cec017249459
7
- data.tar.gz: 4c12e055ccc06b235e951b3edeb0f5adad4d04f58a2ff9a282827302199c1422bcb8f481884313143e9c32046e9599117e24fa6a9c4f6e6d8c92ceaf19d64b18
6
+ metadata.gz: 3df6102dcf37884530d91c9eb42876089db2b898c88199635e18ad0c7097dd3d809fcd60e8144185906dbd50f385c1a33d2056863eece3a7d9f5509457384be2
7
+ data.tar.gz: 4596fd7f51c8fad31481b3b1fba27b8c068c8c28f4266f0d9a9804e119d20298445e61f3726259a3f9a928e5944b28951abf93e58879e74780cf57586836ad7e
data/examples/upload.rb CHANGED
@@ -16,4 +16,7 @@ class Upload < Balloon::Base
16
16
  end
17
17
 
18
18
  upload = Upload.new("input.jpg")
19
- upload.upload_store
19
+ p upload.upload_store
20
+ p upload.from_store
21
+ p upload.path
22
+ p upload.local_path
data/lib/balloon/base.rb CHANGED
@@ -40,6 +40,14 @@ module Balloon
40
40
  storage_engine.retrieve!(size_name)
41
41
  end
42
42
 
43
+ def path(size_name = nil)
44
+ storage_engine.path!(size_name)
45
+ end
46
+
47
+ def local_path(size_name = nil)
48
+ storage_engine.local_path!(size_name)
49
+ end
50
+
43
51
  def upload_delete
44
52
  storage_engine.delete!
45
53
  end
@@ -15,8 +15,8 @@ module Balloon
15
15
  processed_img = handle_original(image, ext)
16
16
  data[:original] = get_image_data(processed_img)
17
17
 
18
- resized_img = handle_resize(image, ext)
19
- data.merge!(resized_img)
18
+ total_size = handle_resize(image, ext, data)
19
+ data[:total_size] = processed_img.size.to_i + total_size.to_i
20
20
 
21
21
  mime_type = processed_img.mime_type
22
22
  extension = FileExtension.get_extension(mime_type)
@@ -45,14 +45,14 @@ module Balloon
45
45
  cache_file = File.join(cache_path, "#{file.basename}.#{ext}")
46
46
  convert << cache_file
47
47
  convert.call
48
-
48
+
49
49
  return MiniMagick::Image.open(cache_file)
50
50
  end
51
51
 
52
- def handle_resize(file, ext)
53
- return {} unless self.respond_to?(:uploader_size)
54
- return {} if store_storage.to_s == "upyun" && upyun_is_image
55
- data = {}
52
+ def handle_resize(file, ext, data)
53
+ return unless self.respond_to?(:uploader_size)
54
+ return if store_storage.to_s == "upyun" && upyun_is_image
55
+ total_size = 0
56
56
 
57
57
  uploader_size.each do |size, o|
58
58
  img = MiniMagick::Image.open(file.path)
@@ -71,13 +71,14 @@ module Balloon
71
71
 
72
72
  processed_img = MiniMagick::Image.open(cache_file)
73
73
  data[size] = get_image_data(processed_img)
74
+ total_size += processed_img.size
74
75
  end
75
76
 
76
- return data
77
+ return total_size
77
78
  end
78
79
 
79
80
  def resize(convert, image, size)
80
- width, height, symbol = size[:width], size[:height], size[:symbol]
81
+ width, height, symbol = size[:width], size[:height], size[:symbol]
81
82
 
82
83
  if !symbol.empty? || width.match(/\%/) || height.match(/\%/)
83
84
  if width == height
@@ -114,7 +115,7 @@ module Balloon
114
115
  shave_off = ((w - h) / 2).round
115
116
  convert.shave "#{shave_off}x0"
116
117
  return
117
- end
118
+ end
118
119
 
119
120
  shave_off = ((h - w) / 2).round
120
121
  convert.shave "0x#{shave_off}"
@@ -31,11 +31,21 @@ module Balloon
31
31
  return { filename: original_file, basename: store_name}
32
32
  end
33
33
 
34
- def retrieve!(size_name = nil)
34
+ def path!(size_name = nil)
35
35
  return "" if !upload_file
36
36
  path = ::File.join upload_dir, store_filename(size_name)
37
- return "/" + path if @uploader.asset_host.nil?
38
- @uploader.asset_host + "/" + path
37
+ return "/#{path}"
38
+ end
39
+
40
+ def local_path!(size_name = nil)
41
+ path = ::File.join @uploader.store_dir, path!(size_name)
42
+ return ::File.expand_path(::File.join(@uploader.root, path))
43
+ end
44
+
45
+ def retrieve!(size_name = nil)
46
+ path = path!(size_name)
47
+ return path if @uploader.asset_host.nil?
48
+ return "#{@uploader.asset_host}#{path}"
39
49
  end
40
50
 
41
51
  def delete!
data/lib/balloon/up.rb CHANGED
@@ -90,6 +90,24 @@ module Balloon
90
90
  storage_engine.retrieve!(size_name)
91
91
  end
92
92
 
93
+ def path(size_name = nil)
94
+ return "" if !respond_to?(:file_name) || file_name.nil?
95
+ extension = self.file_name.to_s.match(%r"(?!\\.{1})\\w{2,}$")
96
+ basename = self.file_name.to_s.gsub(%r"\\.{1}\\w{2,}$",'')
97
+ @meta = { basename: basename, extension: extension.to_s }
98
+ set_storage_engine
99
+ storage_engine.path!(size_name)
100
+ end
101
+
102
+ def local_path(size_name = nil)
103
+ return "" if !respond_to?(:file_name) || file_name.nil?
104
+ extension = self.file_name.to_s.match(%r"(?!\\.{1})\\w{2,}$")
105
+ basename = self.file_name.to_s.gsub(%r"\\.{1}\\w{2,}$",'')
106
+ @meta = { basename: basename, extension: extension.to_s }
107
+ set_storage_engine
108
+ storage_engine.local_path!(size_name)
109
+ end
110
+
93
111
  def uploader_delete
94
112
  return if !respond_to?(:file_name) || file_name.nil?
95
113
  extension = self.file_name.to_s.match(%r"(?!\\.{1})\\w{2,}$")
@@ -18,7 +18,17 @@ module Balloon
18
18
  end
19
19
 
20
20
  def save_to_cache(up_file)
21
- uploader_file = up_file.is_a?(String) && up_file.include?("://") ? down_url(up_file) : up_file
21
+ upload_data = {}
22
+ uploader_file = up_file
23
+
24
+ if up_file.is_a?(String) && up_file.include?("://")
25
+ upload_data[:remote_url] = up_file
26
+ uploader_file = down_url(up_file)
27
+ end
28
+
29
+ if up_file.is_a?(ActionDispatch::Http::UploadedFile)
30
+ upload_data[:original_filename] = up_file.original_filename
31
+ end
22
32
 
23
33
  uploader_file_ext = Balloon::FileExtension.new(uploader_file)
24
34
  file_mime_type = uploader_file_ext.mime_type
@@ -44,7 +54,8 @@ module Balloon
44
54
  size: @cache_meta[:size],
45
55
  mime_type: @cache_meta[:mime_type],
46
56
  extension: @cache_meta[:extension],
47
- data: @cache_meta[:data]
57
+ upload_data: upload_data,
58
+ data: upload_data.merge(@cache_meta[:data])
48
59
  }
49
60
  end
50
61
 
@@ -1,3 +1,3 @@
1
1
  module Balloon
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balloon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yeeli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport