<commit_before>require "sinatra/base"
require "json"
require "fileutils"
require "resque"
require "redis"
require "openssl"
require "base64"
require 'sinatra/cross_origin'

require './page'
require './pagerepository'
require './index_job'

class GitHubPagesSearch < Sinatra::Base
  register Sinatra::CrossOrigin

  set :root, File.dirname(__FILE__)

  set :repository, PageRepository.new
  set :per_page,   10

  configure do

    if ENV['RACK_ENV'] == "production"
      uri = URI.parse( ENV[ "REDISTOGO_URL" ])
      REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => <PASSWORD>)
      Resque.redis = REDIS
    else
      Resque.redis = Redis.new
    end

    set :allow_origin, :all

    # HTTP methods allowed
    set :allow_methods, [:get]

    # Allow cookies to be sent with the requests
    set :allow_credentials, true
  end

  before do
    # trim trailing slashes
    request.path_info.sub! %r{/$}, ''
    pass unless %w[index].include? request.path_info.split('/')[1]
    # ensure signature is correct
    request.body.rewind
    payload_body = request.body.read
    verify_signature(payload_body)
    # keep some important vars
    @payload = JSON.parse payload_body
    @repo = "#{@payload["repository"]["full_name"]}"
    check_params
  end

  get "/" do
    "I think you misunderstand how to use this."
  end

  get "/search" do
    cross_origin

    content_type :json
    @page  = [ params[:p].to_i, 1 ].max

    @pages = GitHubPagesSearch.repository.search \
               query: ->(q, t) do<commit_msg>:trollface:<commit_after>require "sinatra/base"
require "json"
require "fileutils"
require "resque"
require "redis"
require "openssl"
require "base64"
require 'sinatra/cross_origin'

require './page'
require './pagerepository'
require './index_job'

class GitHubPagesSearch < Sinatra::Base
  register Sinatra::CrossOrigin

  set :root, File.dirname(__FILE__)

  set :repository, PageRepository.new
  set :per_page,   10

  configure do

    if ENV['RACK_ENV'] == "production"
      uri = URI.parse( ENV[ "REDISTOGO_URL" ])
      REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => <PASSWORD>)
      Resque.redis = REDIS
    else
      Resque.redis = Redis.new
    end
  end

  before do
    # trim trailing slashes
    request.path_info.sub! %r{/$}, ''
    pass unless %w[index].include? request.path_info.split('/')[1]
    # ensure signature is correct
    request.body.rewind
    payload_body = request.body.read
    verify_signature(payload_body)
    # keep some important vars
    @payload = JSON.parse payload_body
    @repo = "#{@payload["repository"]["full_name"]}"
    check_params
  end

  get "/" do
    "I think you misunderstand how to use this."
  end

  get "/search" do
    cross_origin :allow_origin => '*'

    content_type :json
    @page  = [ params[:p].to_i, 1 ].max

    @pages = GitHubPagesSearch.repository.search \
               query: ->(q, t) do
{'fraction_non_alphanumeric': 0.12491467576791809, 'fraction_numerical': 0.004095563139931741, 'mean_word_length': 3.181169757489301, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '1278790', 'n_tokens_mistral': 986, 'n_tokens_neox': 949, 'n_words': 252}