<commit_before>require 'sinatra/base'
require 'hide'

module Hide

  class Server < Sinatra::Base

    enable :logging, :show_exceptions

    configure :production, :development do
      require File.expand_path('../../../config', __FILE__)
    end

    configure do
      set :website_path,        Hide.config(:path)
      set :website_directories, Hide.config(:directories)
    end

    use Rack::Auth::Basic, "Hide Server" do |username, password|
      Hide.config(:server)[:username] == username && Hide.config(:server)[:password] == password
    end

    post '/update' do
      begin
        json = Yajl::Parser.parse(params[:payload])
        before, after = json['before'], json['after']
        # p [before, after]

        site     = Hide::Site.new(settings.website_path, :pages_directories => settings.website_directories)
        @indexer = Hide::Indexer.new site, 'elastic-search-website'
        @indexer.update! before, after
        
      rescue Yajl::ParseError
        STEDRR.puts params[:payload]
        error 500, "Invalid JSON"
      rescue Hide::GitError
        STEDRR.puts params[:payload]
        error 500, "Invalid JSON payload -- shas missing?"
      end
    end

  end

end

Hide::Server.run! if __FILE__ == $0<commit_msg>[FIX] STEDDR is not STDERR<commit_after>require 'sinatra/base'
require 'hide'

module Hide

  class Server < Sinatra::Base

    enable :logging, :show_exceptions

    configure :production, :development do
      require File.expand_path('../../../config', __FILE__)
    end

    configure do
      set :website_path,        Hide.config(:path)
      set :website_directories, Hide.config(:directories)
    end

    use Rack::Auth::Basic, "Hide Server" do |username, password|
      Hide.config(:server)[:username] == username && Hide.config(:server)[:password] == password
    end

    post '/update' do
      begin
        json = Yajl::Parser.parse(params[:payload])
        before, after = json['before'], json['after']
        # p [before, after]

        site     = Hide::Site.new(settings.website_path, :pages_directories => settings.website_directories)
        @indexer = Hide::Indexer.new site, 'elastic-search-website'
        @indexer.update! before, after
        
      rescue Yajl::ParseError
        STDERR.puts params[:payload]
        error 500, "Invalid JSON"
      rescue Hide::GitError
        STDERR.puts params[:payload]
        error 500, "Invalid JSON payload -- shas missing?"
      end
    end

  end

end

Hide::Server.run! if __FILE__ == $0
{'fraction_non_alphanumeric': 0.12385867407701469, 'fraction_numerical': 0.0055577610162763, 'mean_word_length': 2.7781109445277363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6915396', 'n_tokens_mistral': 793, 'n_tokens_neox': 733, 'n_words': 187}