<commit_before>require 'sinatra'
require 'mini_magick'
require 'json'
require 'securerandom'

class ImagesApp < Sinatra::Base
  ALLOWED = %w(image/png image/bmp image/gif image/jpeg)

  def generate_name
    SecureRandom.hex
  end

  def valid?(image)
    image.valid? && ALLOWED.include?(image.mime_type)
  end

  def valid_request?(params)
    params['media'].is_a?(Hash) && File.exists?(params['media'][:tempfile])
  end

  post '/upload' do
    halt 415, 'Invalid request.' unless valid_request? params

    tempfile = params['media'][:tempfile]

    begin
      image = MiniMagick::Image.read(tempfile.read)
    rescue MiniMagick::Invalid
      halt 415, 'The wrong image.'
    end

    filename = "#{generate_name}.#{image['format'].downcase}"
    fullpath = "#{settings.root}/images/#{filename}"<commit_msg>remove unused method and constant<commit_after>require 'sinatra'
require 'mini_magick'
require 'json'
require 'securerandom'

class ImagesApp < Sinatra::Base

  def generate_name
    SecureRandom.hex
  end

  def valid_request?(params)
    params['media'].is_a?(Hash) && File.exists?(params['media'][:tempfile])
  end

  post '/upload' do
    halt 415, 'Invalid request.' unless valid_request? params

    tempfile = params['media'][:tempfile]

    begin
      image = MiniMagick::Image.read(tempfile.read)
    rescue MiniMagick::Invalid
      halt 415, 'The wrong image.'
    end

    filename = "#{generate_name}.#{image['format'].downcase}"
    fullpath = "#{settings.root}/images/#{filename}"
{'fraction_non_alphanumeric': 0.1390728476821192, 'fraction_numerical': 0.007947019867549669, 'mean_word_length': 4.122033898305085, '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': '4946950', 'n_tokens_mistral': 500, 'n_tokens_neox': 480, 'n_words': 107}