Sha256: 7f284224ade5541895c71c4ef98d7fcea474d44ad4d198523a798741fcaa1c04

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

module Script
  module Layers
    module Infrastructure
      class ScriptUploader
        def initialize(script_service)
          @script_service = script_service
        end

        def upload(script_content)
          upload_details = @script_service.generate_module_upload_details
          url = URI(upload_details[:url])

          https = Net::HTTP.new(url.host, url.port)
          https.use_ssl = true

          request = Net::HTTP::Put.new(url)
          request["Content-Type"] = "application/wasm"

          upload_details[:headers].each do |header, value|
            request[header] = value
          end

          request.body = script_content

          response = https.request(request)
          raise Errors::ScriptTooLargeError, upload_details[:max_size] if script_too_large?(response)
          raise Errors::ScriptUploadError unless response.code == "200"

          upload_details[:url]
        end

        private

        def script_too_large?(response)
          response.code == "400" && response.body.include?("EntityTooLarge")
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
shopify-cli-2.25.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.24.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.23.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.22.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.21.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.20.1 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.20.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.19.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.18.1 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.18.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.17.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.16.1 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.16.0 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.6 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.5 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.4 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.3 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.2 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.1 lib/project_types/script/layers/infrastructure/script_uploader.rb
shopify-cli-2.15.0 lib/project_types/script/layers/infrastructure/script_uploader.rb