<commit_before>class Checklist::DownloadsController < ApplicationController
  rescue_from ActiveRecord::RecordNotFound, :with => :not_found

  # GET downloads/
  #
  # Lists a set of downloads for a given list of IDs
  def index
    ids = params[:ids] || ""
    @downloads = Download.where(:id => ids).order('updated_at DESC').limit(5)
    @downloads.map! { |v| v.attributes.except("filename", "path") }
    @downloads.each do |v|
      v["updated_at"] = v["updated_at"].strftime("%A, %e %b %Y %H:%M")
    end

    render :text => @downloads.to_json
  end

  # POST downloads/
  def create
    @download = Download.create(params[:download])
    DownloadWorker.perform_async(@download.id, params)

    @download = @download.attributes.except("filename", "path")
    @download["updated_at"] = @download["updated_at"].strftime("%A, %e %b %Y %H:%M")

    render :text => @download.to_json
  end

  # GET downloads/:id/
  def show
    @download = Download.find(params[:id])

    render :text => {status: @download.status}.to_json
  end

  # GET downloads/:id/download
  def download
    @download = Download.find(params[:id])

    if @download.status == Download::COMPLETED
      # Update access time for cache cleaning purposes
      FileUtils.touch(@download.path)

      send_file(Pathname.new(@download.path).realpath,
        :filename => @download.filename,
        :type => @download.format)
    else
      render :text => {error: "Download not processed"}.to_json
    end
  end

  def download_index
    @doc = download_module::Index.new(params)
    send_download
  end

  def download_history
    @doc = download_module::History.new(params)
    send_download
  end

  private

  def download_module
    format_mapping = {
      "pdf" => Checklist::Pdf,
      "csv" => Checklist::Csv,
      "json" => Checklist::Json
    }
    format_mapping[params[:format]]
  end<commit_msg>fix exception when format not specified<commit_after>class Checklist::DownloadsController < ApplicationController
  rescue_from ActiveRecord::RecordNotFound, :with => :not_found

  # GET downloads/
  #
  # Lists a set of downloads for a given list of IDs
  def index
    ids = params[:ids] || ""
    @downloads = Download.where(:id => ids).order('updated_at DESC').limit(5)
    @downloads.map! { |v| v.attributes.except("filename", "path") }
    @downloads.each do |v|
      v["updated_at"] = v["updated_at"].strftime("%A, %e %b %Y %H:%M")
    end

    render :text => @downloads.to_json
  end

  # POST downloads/
  def create
    @download = Download.create(params[:download])
    DownloadWorker.perform_async(@download.id, params)

    @download = @download.attributes.except("filename", "path")
    @download["updated_at"] = @download["updated_at"].strftime("%A, %e %b %Y %H:%M")

    render :text => @download.to_json
  end

  # GET downloads/:id/
  def show
    @download = Download.find(params[:id])

    render :text => {status: @download.status}.to_json
  end

  # GET downloads/:id/download
  def download
    @download = Download.find(params[:id])

    if @download.status == Download::COMPLETED
      # Update access time for cache cleaning purposes
      FileUtils.touch(@download.path)

      send_file(Pathname.new(@download.path).realpath,
        :filename => @download.filename,
        :type => @download.format)
    else
      render :text => {error: "Download not processed"}.to_json
    end
  end

  def download_index
    @doc = download_module::Index.new(params)
    send_download
  end

  def download_history
    @doc = download_module::History.new(params)
    send_download
  end

  private

  def download_module
    format_mapping = {
      "pdf" => Checklist::Pdf,
      "csv" => Checklist::Csv,
      "json" => Checklist::Json
    }
    format_mapping[params[:format]] || Checklist::Pdf
  end
{'fraction_non_alphanumeric': 0.13834823776959496, 'fraction_numerical': 0.0005260389268805891, 'mean_word_length': 3.442757009345794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 84, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5824405', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1181, 'n_words': 271}