<commit_before>class UserImportFilesController < ApplicationController
  load_and_authorize_resource
  before_filter :prepare_options, only: [:new, :edit]

  # GET /user_import_files
  # GET /user_import_files.json
  def index
    @user_import_files = UserImportFile.page(params[:page])

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @user_import_files }
    end
  end

  # GET /user_import_files/1
  # GET /user_import_files/1.json
  def show
    if @user_import_file.user_import.path
      unless ENV['ENJU_STORAGE'] == 's3'
        file = @user_import_file.user_import.path
      end
    end

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user_import_file }
      format.download {
        if ENV['ENJU_STORAGE'] == 's3'
          redirect_to @user_import_file.user_import.expiring_url(10)
        else
          send_file file, filename: @user_import_file.user_import_file_name, type: 'application/octet-stream'
        end
      }
    end
  end

  # GET /user_import_files/new
  # GET /user_import_files/new.json<commit_msg>use send_data to download a file from s3<commit_after>class UserImportFilesController < ApplicationController
  load_and_authorize_resource
  before_filter :prepare_options, only: [:new, :edit]

  # GET /user_import_files
  # GET /user_import_files.json
  def index
    @user_import_files = UserImportFile.page(params[:page])

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @user_import_files }
    end
  end

  # GET /user_import_files/1
  # GET /user_import_files/1.json
  def show
    if @user_import_file.user_import.path
      unless ENV['ENJU_STORAGE'] == 's3'
        file = @user_import_file.user_import.path
      end
    end

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user_import_file }
      format.download {
        if ENV['ENJU_STORAGE'] == 's3'
          send_data Faraday.get(@user_import_file.user_export.expiring_url).body.force_encoding('UTF-8'),
        else
          send_file file, filename: @user_import_file.user_import_file_name, type: 'application/octet-stream'
        end
      }
    end
  end

  # GET /user_import_files/new
  # GET /user_import_files/new.json
{'fraction_non_alphanumeric': 0.09188955996548749, 'fraction_numerical': 0.005176876617773943, 'mean_word_length': 3.068421052631579, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2882414', 'n_tokens_mistral': 793, 'n_tokens_neox': 780, 'n_words': 150}