<commit_before>class DocumentsController < ApplicationController

  @@storage_location = '/tmp/rails'

  # POST /documents
  def create
    file = params[:file]
    file_name = sanitize_filename(file.original_filename)
    File.open("#{@@storage_location}/#{file_name}", 'wb') { |f| f.write(file.read) }

    # TODO add file metadata

    render json: { }, status: :ok
  end

  # GET /documents/:id
  def show
    send_file "#{@@storage_location}/#{params[:id]}.#{params[:format]}", disposition: 'attachment'
  end

  private

  def sanitize_filename(file_name)
    # get only the filename, not the whole path (from IE)
    just_filename = File.basename(file_name)
    # replace all non alphanumeric, underscore or periods with underscore
    just_filename.sub(/[^\w\.\-]/,'_')
  end

end<commit_msg>Add file deletion to document resource<commit_after>class DocumentsController < ApplicationController

  @@storage_location = '/tmp/rails'

  # POST /documents
  def create
    file = params[:file]
    file_name = sanitize_filename(file.original_filename)
    File.open("#{@@storage_location}/#{file_name}", 'wb') { |f| f.write(file.read) }

    # TODO add file metadata

    render json: nil, status: :ok
  end

  # GET /documents/:id
  def show
    send_file "#{@@storage_location}/#{params[:id]}.#{params[:format]}", disposition: 'attachment'
  end

  # DELETE /documents/:id
  def destroy
    File.delete "#{@@storage_location}/#{params[:id]}.#{params[:format]}"

    render json: nil, status: :no_content
  end

  private

  def sanitize_filename(file_name)
    # get only the filename, not the whole path (from IE)
    just_filename = File.basename(file_name)
    # replace all non alphanumeric, underscore or periods with underscore
    just_filename.sub(/[^\w\.\-]/,'_')
  end

end
{'fraction_non_alphanumeric': 0.13862493012856344, 'fraction_numerical': 0.0, 'mean_word_length': 3.877384196185286, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4138163', 'n_tokens_mistral': 583, 'n_tokens_neox': 563, 'n_words': 141}