Sha256: 643a274830eceef79240bc5e4014c43fb5af064f3a243a3ba44a406bcf4758d7

Contents?: true

Size: 1.71 KB

Versions: 465

Compression:

Stored size: 1.71 KB

Contents

require 'fileutils'

module Spaceship
  # a wrapper around the concept of file required to make uploads to DU
  class UploadFile
    attr_reader :file_path
    attr_reader :file_name
    attr_reader :file_size
    attr_reader :content_type
    attr_reader :bytes

    class << self
      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

      # 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
      def remove_alpha_channel(original)
        path = "/tmp/#{Digest::MD5.hexdigest(original)}.png"
        FileUtils.copy(original, path)
        if mac? # sips is only available on macOS
          `sips -s format bmp '#{path}' &> /dev/null` # &> /dev/null since there is warning because of the extension
          `sips -s format png '#{path}'`
        end
        return path
      end

      def mac?
        (/darwin/ =~ RUBY_PLATFORM) != nil
      end
    end

    private

    def initialize(args)
      args.each do |k, v|
        instance_variable_set("@#{k}", v) unless v.nil?
      end
    end
  end
end

Version data entries

465 entries across 465 versions & 2 rubygems

Version Path
fastlane-2.20.0.beta.20170305010057 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.20.0.beta.20170304010023 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.20.0.beta.20170303010054 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.20.0.beta.20170302010029 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.1 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170301010932 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170228010016 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170227010016 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170226010028 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170225010031 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170224010025 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.3 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170223010028 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.2 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.19.0.beta.20170222010016 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.1 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.0 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.0.beta.20170221010026 spaceship/lib/spaceship/du/upload_file.rb
fastlane-2.18.0.beta.20170220010017 spaceship/lib/spaceship/du/upload_file.rb