<commit_before>module SS::Model::File
  extend ActiveSupport::Concern
  extend SS::Translation
  include SS::Document
  include SS::Reference::User
  include SS::FileFactory
  include SS::ExifGeoLocation
  include ActiveSupport::NumberHelper

  attr_accessor :in_file, :resizing, :unnormalize

  included do
    cattr_accessor(:root, instance_accessor: false) { "#{Rails.root}/private/files" }
    store_in collection: "ss_files"

    seqid :id
    field :model, type: String
    field :state, type: String, default: "closed"
    field :name, type: String
    field :filename, type: String
    field :size, type: Integer
    field :content_type, type: String

    belongs_to :site, class_name: "SS::Site"

    belongs_to :owner_item, class_name: "Object", polymorphic: true

    attr_accessor :in_data_url

    permit_params :in_file, :state, :name, :filename, :resizing, :in_data_url

    before_validation :set_filename, if: ->{ in_file.present? }
    before_validation :normalize_filename, if: -> { !unnormalize }

    validates :model, presence: true
    validates :state, presence: true
    validates :filename, presence: true, if: ->{ in_file.blank? && in_files.blank? }
    validates :content_type, presence: true
    validate :validate_filename, if: ->{ filename.present? }
    validates_with SS::FileSizeValidator, if: ->{ size.present? }<commit_msg>[fix] ss_file content_type validation (#2928)<commit_after>module SS::Model::File
  extend ActiveSupport::Concern
  extend SS::Translation
  include SS::Document
  include SS::Reference::User
  include SS::FileFactory
  include SS::ExifGeoLocation
  include ActiveSupport::NumberHelper

  attr_accessor :in_file, :resizing, :unnormalize

  included do
    cattr_accessor(:root, instance_accessor: false) { "#{Rails.root}/private/files" }
    store_in collection: "ss_files"

    seqid :id
    field :model, type: String
    field :state, type: String, default: "closed"
    field :name, type: String
    field :filename, type: String
    field :size, type: Integer
    field :content_type, type: String

    belongs_to :site, class_name: "SS::Site"

    belongs_to :owner_item, class_name: "Object", polymorphic: true

    attr_accessor :in_data_url

    permit_params :in_file, :state, :name, :filename, :resizing, :in_data_url

    before_validation :set_filename, if: ->{ in_file.present? }
    before_validation :normalize_filename, if: -> { !unnormalize }

    validates :model, presence: true
    validates :state, presence: true
    validates :filename, presence: true, if: ->{ in_file.blank? && in_files.blank? }
    validates :content_type, presence: true, if: ->{ in_file.blank? && in_files.blank? }
    validate :validate_filename, if: ->{ filename.present? }
    validates_with SS::FileSizeValidator, if: ->{ size.present? }
{'fraction_non_alphanumeric': 0.11699463327370305, 'fraction_numerical': 0.0014311270125223613, 'mean_word_length': 4.482352941176471, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1670277', 'n_tokens_mistral': 898, 'n_tokens_neox': 872, 'n_words': 229}