<commit_before>module AssetsCommonExtension


  def show_via_url asset, content_blob=nil
    content_blob = content_blob.nil? ? asset.content_blob : content_blob
    code = url_response_code(content_blob.url)
    if (["302", "401"].include?(code))
      redirect_to(content_blob.url, :target=>"_blank")
    elsif code=="404"
      flash[:error]="This item is referenced at a remote location, which is currently unavailable"
      redirect_to polymorphic_path(asset.parent, {:version=>asset.version})
    else
      downloader=Seek::RemoteDownloader.new
      data_hash = downloader.get_remote_data content_blob.url
      send_file data_hash[:data_tmp_path], :filename => data_hash[:filename] || content_blob.original_filename, :content_type => data_hash[:content_type] || content_blob.content_type, :disposition => 'inline'
    end
  end

  def calculate_params symbol
    i = 0
    local_set = []
    url_set = []
    while !params[symbol].blank?
      if !params[symbol]['file_'+i.to_s].nil?
        if params[symbol]['file_'+i.to_s] != ""
          local_set << params[symbol]['file_'+i.to_s]
        end
        params[symbol].delete 'file_'+i.to_s
      end
      if !params[symbol]['url_'+i.to_s].nil?
        if params[symbol]['url_'+i.to_s] != ""
          url_set << params[symbol]['url_'+i.to_s]
        end
        params[symbol].delete 'url_'+i.to_s
      end
      i += 1
    end

    return [local_set, url_set]
  end

  def handle_batch_data render_action_on_error=:new
    #FIXME: too many nested if,else and rescue blocks. This method needs refactoring.
    c = self.controller_name.downcase
    @content_types = []
    @original_filenames = []
    @tmp_io_objects_localfile = []
    @tmp_io_objects_url = []
    @data_urls = []
    symb = c.singularize.to_sym
    object = eval("@#{c.singularize}")
    params_files = calculate_params(:content_blob)
    params_data = params_files.first
    params_url = params_files.second
    params_image_file = params[controller_name.singularize+'_image'].nil? ? nil : params[controller_name.singular+'_image']['image_file']

    if render_action_on_error==:new || render_action_on_error.nil?
      params_files = params_data + params_url
    elsif render_action_on_error==:edit
      params_files = object.content_blobs
    end<commit_msg>singularize instead of singular<commit_after>module AssetsCommonExtension


  def show_via_url asset, content_blob=nil
    content_blob = content_blob.nil? ? asset.content_blob : content_blob
    code = url_response_code(content_blob.url)
    if (["302", "401"].include?(code))
      redirect_to(content_blob.url, :target=>"_blank")
    elsif code=="404"
      flash[:error]="This item is referenced at a remote location, which is currently unavailable"
      redirect_to polymorphic_path(asset.parent, {:version=>asset.version})
    else
      downloader=Seek::RemoteDownloader.new
      data_hash = downloader.get_remote_data content_blob.url
      send_file data_hash[:data_tmp_path], :filename => data_hash[:filename] || content_blob.original_filename, :content_type => data_hash[:content_type] || content_blob.content_type, :disposition => 'inline'
    end
  end

  def calculate_params symbol
    i = 0
    local_set = []
    url_set = []
    while !params[symbol].blank?
      if !params[symbol]['file_'+i.to_s].nil?
        if params[symbol]['file_'+i.to_s] != ""
          local_set << params[symbol]['file_'+i.to_s]
        end
        params[symbol].delete 'file_'+i.to_s
      end
      if !params[symbol]['url_'+i.to_s].nil?
        if params[symbol]['url_'+i.to_s] != ""
          url_set << params[symbol]['url_'+i.to_s]
        end
        params[symbol].delete 'url_'+i.to_s
      end
      i += 1
    end

    return [local_set, url_set]
  end

  def handle_batch_data render_action_on_error=:new
    #FIXME: too many nested if,else and rescue blocks. This method needs refactoring.
    c = self.controller_name.downcase
    @content_types = []
    @original_filenames = []
    @tmp_io_objects_localfile = []
    @tmp_io_objects_url = []
    @data_urls = []
    symb = c.singularize.to_sym
    object = eval("@#{c.singularize}")
    params_files = calculate_params(:content_blob)
    params_data = params_files.first
    params_url = params_files.second
    params_image_file = params[controller_name.singularize+'_image'].nil? ? nil : params[controller_name.singularize+'_image']['image_file']

    if render_action_on_error==:new || render_action_on_error.nil?
      params_files = params_data + params_url
    elsif render_action_on_error==:edit
      params_files = object.content_blobs
    end
{'fraction_non_alphanumeric': 0.12014747343309477, 'fraction_numerical': 0.004771199306007373, 'mean_word_length': 3.6774847870182557, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5500705', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1491, 'n_words': 270}