<commit_before>class DocumentsController < ApplicationController
  def new
    @token = params[:user_token]
    @number_of_docs = params[:number_of_docs]
  end

  def create
    puts params.to_hash
    token = params[:user_token]
    doc_number = params[:doc_number].to_i
    redis = Redis.new(:url => URI.parse(ENV['REDISTOGO_URL']))
    doc = Calfresh::VerificationDoc.new(params)
    image_binary = IO.binread(doc.original_file_path)
    key_base = "#{token}_#{doc_number}"
    filename = params["identification"].original_filename.gsub(/[^a-zA-Z0-9_.]+/,"")
    redis.set(key_base + "_binary", image_binary)
    redis.expire(key_base + "_binary", redis_expiration_time)
    redis.set(key_base + "_filename", filename)
    redis.expire(key_base + "_filename", redis_expiration_time)
    new_number_of_docs = doc_number + 1
    redirect_to "/documents/#{params[:user_token]}/#{new_number_of_docs}"
  end

  def submit
    token = params[:user_token]
    max_doc_index = params[:doc_number].to_i - 1
    redis = Redis.new(:url => URI.parse(ENV['REDISTOGO_URL']))
    file_paths_array = Array.new
    (0..max_doc_index).to_a.each do |index|
      # Get binary from Redis
      binary = redis.get("#{token}_#{index}_binary")
      # Get filename from Redis
      filename = redis.get("#{token}_#{index}_filename")
      # Write file to /tmp with proper extension
      temp_file_path = "/tmp/" + token + filename
      File.open(temp_file_path, 'wb') do |file|
        file.write(binary)
      end
      # Add full path for new file to array<commit_msg>Temp fix, use random value as file name for docs<commit_after>class DocumentsController < ApplicationController
  def new
    @token = params[:user_token]
    @number_of_docs = params[:number_of_docs]
  end

  def create
    puts params.to_hash
    token = params[:user_token]
    doc_number = params[:doc_number].to_i
    redis = Redis.new(:url => URI.parse(ENV['REDISTOGO_URL']))
    doc = Calfresh::VerificationDoc.new(params)
    image_binary = IO.binread(doc.original_file_path)
    key_base = "#{token}_#{doc_number}"
    filename = params["identification"].original_filename.gsub(/[^a-zA-Z0-9_.]+/,"")
    redis.set(key_base + "_binary", image_binary)
    redis.expire(key_base + "_binary", redis_expiration_time)
    redis.set(key_base + "_filename", filename)
    redis.expire(key_base + "_filename", redis_expiration_time)
    new_number_of_docs = doc_number + 1
    redirect_to "/documents/#{params[:user_token]}/#{new_number_of_docs}"
  end

  def submit
    token = params[:user_token]
    max_doc_index = params[:doc_number].to_i - 1
    redis = Redis.new(:url => URI.parse(ENV['REDISTOGO_URL']))
    file_paths_array = Array.new
    (0..max_doc_index).to_a.each do |index|
      # Get binary from Redis
      binary = redis.get("#{token}_#{index}_binary")
      # Get filename from Redis
      filename = redis.get("#{token}_#{index}_filename")
      # Write file to /tmp with proper extension
      #temp_file_path = "/tmp/" + token + filename
      temp_file_name = SecureRandom.hex
      temp_file_path = "/tmp/" + temp_file_name
      File.open(temp_file_path, 'wb') do |file|
        file.write(binary)
      end
      # Add full path for new file to array
{'fraction_non_alphanumeric': 0.13011152416356878, 'fraction_numerical': 0.0030978934324659233, 'mean_word_length': 3.713868613138686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116633', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1090, 'n_words': 211}