<commit_before>require 'error_codes'

module Api
  module V1
    class BaseApiController < ApplicationController
      include BaseDoc

      before_filter :remove_empty_params_and_headers
      before_filter :set_custom_response_headers
      before_filter :authenticate_from_token!, except: [:me, :options]
      before_action :set_paper_trail_whodunnit, :store_request

      respond_to :json

      def version
        name = "#{Rails.application.class.parent_name} v#{VERSION}"
        render_success 'version', name
      end

      def me
        header = CONFIG['authorization_header'] || 'X-Token'
        token = request.headers[header]

        if session['check.error']
          message = session['check.error']
          reset_session
          render_error(message, 'UNKNOWN') and return
        end

        if token
          render_user User.where(token: token).last, 'token'
        else
          render_user current_api_user, 'session'
        end
      end

      def log
        begin
          json = JSON.parse(params[:data]).merge({ request: request, source: 'client' })
          logger.info message: json, status: 200
          render_success and return<commit_msg>Ticket #6697: Log current user<commit_after>require 'error_codes'

module Api
  module V1
    class BaseApiController < ApplicationController
      include BaseDoc

      before_filter :remove_empty_params_and_headers
      before_filter :set_custom_response_headers
      before_filter :authenticate_from_token!, except: [:me, :options]
      before_action :set_paper_trail_whodunnit, :store_request

      respond_to :json

      def version
        name = "#{Rails.application.class.parent_name} v#{VERSION}"
        render_success 'version', name
      end

      def me
        header = CONFIG['authorization_header'] || 'X-Token'
        token = request.headers[header]

        if session['check.error']
          message = session['check.error']
          reset_session
          render_error(message, 'UNKNOWN') and return
        end

        if token
          render_user User.where(token: token).last, 'token'
        else
          render_user current_api_user, 'session'
        end
      end

      def log
        begin
          json = JSON.parse(params[:data]).merge({ request: request, source: 'client', user: User.current })
          logger.info message: json, status: 200
          render_success and return
{'fraction_non_alphanumeric': 0.08295501444490301, 'fraction_numerical': 0.004952538175815105, 'mean_word_length': 2.5335276967930027, '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': '243925', 'n_tokens_mistral': 678, 'n_tokens_neox': 657, 'n_words': 165}