<commit_before>require 'sinatra/base'
require 'uri'
require 'entry'
require 'ballot'


class Baked < Sinatra::Base
  use Rack::MethodOverride

  get '/entries' do
    @entries = Entry.all
    haml :'entries/index'
  end

  get '/entries/new' do
    haml :'entries/new'
  end

  get "/entries/:id" do
    @entry = Entry.find(params[:id])
    haml :'entries/show'
  end

  post '/entries' do
    @entry = Entry.new(params[:entry])
    if @entry.save
      redirect "/entries/#{@entry.id}"
    else
      @entries = Entry.all
      haml :'entries/index'
    end
  end

  delete "/entries/:id" do
    if entry = Entry.find(params[:id])
      entry.destroy
    end
    redirect "/entries"
  end

  get '/vote' do
    @entries = Entry.all
    @ballot = Ballot.find_or_initialize_by(:ip => request.ip)
    haml :'votes/new'
  end

  post '/vote' do
    @ballot = Ballot.find_or_create_by(:ip => request.ip)
    @ballot.from_hash(params[:ballot])
    @ballot.save
    redirect '/vote'
  end

  get '/results' do
    @overall = Ballot.overall
    @taste = Ballot.category(:taste)
    @creativity = Ballot.category(:creativity)
    haml :'results/index'
  end

  get '/gridfs/:id/:filename' do
    img = params[:id] + '/' + params[:filename]
    fs = Mongo::GridFileSystem.new(Mongoid.database)
    file = fs.open(img, 'r')
    content_type file.content_type
    file.read
  end

  error Mongoid::Errors::DocumentNotFound do
    raise NotFound
  end
end<commit_msg>Additional GridFS settings<commit_after>require 'sinatra/base'
require 'uri'
require 'entry'
require 'ballot'


class Baked < Sinatra::Base
  use Rack::MethodOverride

  get '/entries' do
    @entries = Entry.all
    haml :'entries/index'
  end

  get '/entries/new' do
    haml :'entries/new'
  end

  get "/entries/:id" do
    @entry = Entry.find(params[:id])
    haml :'entries/show'
  end

  post '/entries' do
    @entry = Entry.new(params[:entry])
    if @entry.save
      redirect "/entries/#{@entry.id}"
    else
      @entries = Entry.all
      haml :'entries/index'
    end
  end

  delete "/entries/:id" do
    if entry = Entry.find(params[:id])
      entry.destroy
    end
    redirect "/entries"
  end

  get '/vote' do
    @entries = Entry.all
    @ballot = Ballot.find_or_initialize_by(:ip => request.ip)
    haml :'votes/new'
  end

  post '/vote' do
    @ballot = Ballot.find_or_create_by(:ip => request.ip)
    @ballot.from_hash(params[:ballot])
    @ballot.save
    redirect '/vote'
  end

  get '/results' do
    @overall = Ballot.overall
    @taste = Ballot.category(:taste)
    @creativity = Ballot.category(:creativity)
    haml :'results/index'
  end

  get '/gridfs/:id/:filename' do
    img = params[:id] + '/' + params[:filename]
    fs = Mongo::GridFileSystem.new(Mongoid.database)
    file = fs.open(img, 'r')
    content_type file.content_type
    headers 'Content-Length' => file.file_length.to_s
    file.read
  end

  error Mongoid::Errors::DocumentNotFound do
    raise NotFound
  end

  error Mongo::GridFileNotFound do
    raise NotFound
  end
end
{'fraction_non_alphanumeric': 0.13528637261356155, 'fraction_numerical': 0.0, 'mean_word_length': 2.8517110266159698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '7495337', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1064, 'n_words': 246}