Class: Spaceship::UploadFile
- Inherits:
-
Object
- Object
- Spaceship::UploadFile
- Defined in:
- lib/spaceship/du/upload_file.rb
Overview
a wrapper around the concept of file required to make uploads to DU
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
Class Method Summary collapse
- .from_path(path) ⇒ Object
-
.remove_alpha_channel(original) ⇒ Object
As things like screenshots and app icon shouldn’t contain the alpha channel This will copy the image into /tmp to remove the alpha channel there That’s done to not edit the original image.
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
10 11 12 |
# File 'lib/spaceship/du/upload_file.rb', line 10 def bytes @bytes end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
9 10 11 |
# File 'lib/spaceship/du/upload_file.rb', line 9 def content_type @content_type end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/spaceship/du/upload_file.rb', line 7 def file_name @file_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
6 7 8 |
# File 'lib/spaceship/du/upload_file.rb', line 6 def file_path @file_path end |
#file_size ⇒ Object (readonly)
Returns the value of attribute file_size.
8 9 10 |
# File 'lib/spaceship/du/upload_file.rb', line 8 def file_size @file_size end |
Class Method Details
.from_path(path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spaceship/du/upload_file.rb', line 13 def from_path(path) raise "Image must exists at path: #{path}" unless File.exist?(path) # md5 from original. keeping track of md5s allows to skip previously uploaded in deliver content_md5 = Spaceship::Utilities.md5digest(path) path = remove_alpha_channel(path) if File.extname(path).casecmp('.png').zero? content_type = Utilities.content_type(path) self.new( file_path: path, file_name: 'ftl_' + content_md5 + '_' + File.basename(path), file_size: File.size(path), content_type: content_type, bytes: File.read(path) ) end |
.remove_alpha_channel(original) ⇒ Object
As things like screenshots and app icon shouldn’t contain the alpha channel This will copy the image into /tmp to remove the alpha channel there That’s done to not edit the original image
33 34 35 36 37 38 39 |
# File 'lib/spaceship/du/upload_file.rb', line 33 def remove_alpha_channel(original) path = "/tmp/#{Digest::MD5.hexdigest(original)}.png" FileUtils.copy(original, path) `sips -s format bmp '#{path}' &> /dev/null` # &> /dev/null since there is warning because of the extension `sips -s format png '#{path}'` return path end |