<commit_before>class Ecm::Pictures::Backend::PicturesController < Itsf::Backend::Resource::BaseController
  def self.resource_class
    Ecm::Pictures::Picture
  end

  private

  def request_includes_base64_image?
    params[:ecm_pictures_picture].key?(:image_base64)
  end

  def extract_image_base64(encoded_image)
    decoded_image = Base64.decode64(encoded_image.gsub(/^data\:image\/\w+\;base64\,/, '')).force_encoding('UTF-8')
    content_type = encoded_image.split(';').first.split(':').last
    basename = 'image'
    extension = '.jpg'

    image = Tempfile.new([basename, extension])
    image.write decoded_image
    image.rewind
    image
  end

  def permitted_params
    processed_params = params.deep_dup
    image_base64 = processed_params[:ecm_pictures_picture].try(:delete, :image_base64)
    if image_base64.present?
      image = extract_image_base64(image_base64) 
      processed_params.merge!(image: image)
    end
    processed_params.require(:ecm_pictures_picture)
                      .permit(:picture_gallery_id, :name, :markup_language, :description, :image, :tag_list)
  end
end
<commit_msg>Fixed params for base64 image.<commit_after>class Ecm::Pictures::Backend::PicturesController < Itsf::Backend::Resource::BaseController
  def self.resource_class
    Ecm::Pictures::Picture
  end

  private

  def request_includes_base64_image?
    params[:ecm_pictures_picture].key?(:image_base64)
  end

  def extract_image_base64(encoded_image)
    decoded_image = Base64.decode64(encoded_image.gsub(/^data\:image\/\w+\;base64\,/, '')).force_encoding('UTF-8')
    content_type = encoded_image.split(';').first.split(':').last
    basename = 'image'
    extension = '.jpg'

    image = Tempfile.new([basename, extension])
    image.write decoded_image
    image.rewind
    image
  end

  def permitted_params
    processed_params = params.deep_dup
    image_base64 = processed_params[:ecm_pictures_picture].try(:delete, :image_base64)
    if image_base64.present?
      image = extract_image_base64(image_base64) 
      processed_params[:ecm_pictures_picture].merge!(image: image)
    end
    processed_params.require(:ecm_pictures_picture)
                      .permit(:picture_gallery_id, :name, :markup_language, :description, :image, :tag_list)
  end
end

{'fraction_non_alphanumeric': 0.11754385964912281, 'fraction_numerical': 0.021052631578947368, 'mean_word_length': 4.379716981132075, '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': '12624', 'n_tokens_mistral': 784, 'n_tokens_neox': 731, 'n_words': 112}