<commit_before>require "fluent/config/v1_parser"

class Fluentd::SettingsController < ApplicationController
  before_action :login_required
  before_action :find_fluentd
  before_action :set_config, only: [:show, :edit, :update]

  def show
    @backup_files = @fluentd.agent.backup_files_in_new_order.first(Settings.histories_count_in_preview).map do |file_path|
      Fluentd::SettingArchive::BackupFile.new(file_path)
    end

    @running_backedup_file = Fluentd::SettingArchive::BackupFile.new(@fluentd.agent.running_config_backup_file)
  end

  def edit
  end

  def  update
    if params[:dryrun]
      if dryrun(params[:config])
        flash.now[:success] = I18n.t('messages.dryrun_is_passed')
      else
        flash.now[:danger] = @fluentd.agent.last_error_message
      end
      @config = params[:config]
      render "edit"
    else
      begin
        update_config(params[:config])
        redirect_to daemon_setting_path(@fluentd)
      rescue Fluent::ConfigParseError => e
        @config = params[:config]
        flash.now[:danger] = e.message
        render "edit"
      end
    end
  end

  def source_and_output
    # TODO: error handling if config file has invalid syntax
    # @config = Fluentd::Setting::Config.new(@fluentd.config_file)
  end

  private

  def set_config
    @config = @fluentd.agent.config
  end
<commit_msg>Separate fat action<commit_after>require "fluent/config/v1_parser"

class Fluentd::SettingsController < ApplicationController
  before_action :login_required
  before_action :find_fluentd
  before_action :set_config, only: [:show, :edit, :update]

  def show
    @backup_files = @fluentd.agent.backup_files_in_new_order.first(Settings.histories_count_in_preview).map do |file_path|
      Fluentd::SettingArchive::BackupFile.new(file_path)
    end

    @running_backedup_file = Fluentd::SettingArchive::BackupFile.new(@fluentd.agent.running_config_backup_file)
  end

  def edit
  end

  def  update
    if params[:dryrun]
      handle_dryrun
    else
      handle_update
    end
  end

  def source_and_output
    # TODO: error handling if config file has invalid syntax
    # @config = Fluentd::Setting::Config.new(@fluentd.config_file)
  end

  private

  def set_config
    @config = @fluentd.agent.config
  end

  def handle_dryrun
    if dryrun(params[:config])
      flash.now[:success] = I18n.t('messages.dryrun_is_passed')
    else
      flash.now[:danger] = @fluentd.agent.last_error_message
    end
    @config = params[:config]
    render "edit"
  end

  def handle_update
    update_config(params[:config])
    redirect_to daemon_setting_path(@fluentd)
  rescue Fluent::ConfigParseError => e
    @config = params[:config]
    flash.now[:danger] = e.message
    render "edit"
  end

{'fraction_non_alphanumeric': 0.09541150764748725, 'fraction_numerical': 0.0021849963583394027, 'mean_word_length': 3.7118353344768438, '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': '6262772', 'n_tokens_mistral': 927, 'n_tokens_neox': 895, 'n_words': 172}