Sha256: 010b451393a61cf03e235433d6c9a0a18ac06a3fbe6de81491b22f1d5049a3d4

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

module Decidim
  module ZipStream
    module Writer
      def add_user_data_to_zip_stream(out, user_data)
        user_data.each do |element|
          filename_file = element.last.filename(element.first.parameterize)

          out.put_next_entry(filename_file)
          if element.last.read.presence
            out.write element.last.read
          else
            out.write "No data"
          end
        end
      end

      def add_attachments_to_zip_stream(out, export_attachments)
        export_attachments.each do |attachment_block|
          next if attachment_block.last.nil?

          folder_name = attachment_block.first.parameterize
          attachment_block.last.each do |attachment_uploader|
            next if attachment_uploader.file.nil?

            case attachment_uploader.fog_provider
            when "fog" # file system
              next unless File.exist?(attachment_uploader.file.file)
            when "fog/aws"
              cache_attachment_from_aws(attachment_uploader)
            else
              Rails.logger.info "Carrierwave fog_provider not supported by DataPortabilityExporter for attachment: #{attachment_uploader}"
              next
            end

            attachment_local_path = attachment_uploader.file.file
            out.put_next_entry("#{folder_name}/#{attachment_uploader.file.filename}")
            File.open(attachment_local_path) do |f|
              out << f.read
            end
            CarrierWave.clean_cached_files!
          end
        end
      end

      # Retrieves the file from AWS and stores it into a temporal cache.
      # Once the file is cached, the uploader returns a local `CarrierWave::SanitizedFile`
      # instead of a fog file that acts as a proxy to the remote file.
      def cache_attachment_from_aws(uploader)
        uploader.cache_stored_file!
        uploader.retrieve_from_cache!(uploader.cache_name)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.5 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.4 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.3 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.2 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.1 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.1.rc1 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.23.0 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.22.0 app/services/decidim/zip_stream/zip_stream_writer.rb
decidim-core-0.21.0 app/services/decidim/zip_stream/zip_stream_writer.rb