<commit_before>class Medium < ActiveRecord::Base
  belongs_to :linked, polymorphic: true

  before_save :create_path, unless: :external_link

  def self.inheritance_column
    nil
  end

  ALLOWED_CONTENT_TYPES = %w(image/jpeg image/png image/gif)

  validate do |medium|
    unless ALLOWED_CONTENT_TYPES.include?(medium.content_type)
      medium.errors.add(:content_type, "Content-Type must be one of #{ALLOWED_CONTENT_TYPES.join(", ")}")
    end
  end

  def indifferent_attributes
    attributes.dup.with_indifferent_access
  end

  def create_path
    self.src ||= MediaStorage.stored_path(content_type, type, *path_opts)
  end

  def put_url
    if external_link
      src
    else
      MediaStorage.put_path(src, indifferent_attributes)
    end
  end

  def get_url
    if external_link
      src
    else
      MediaStorage.get_path(src, indifferent_attributes)
    end
  end

  def put_file(file_path)
    MediaStorage.put_file(src, file_path, indifferent_attributes)
  end
end<commit_msg>allow different media types based on import or export paths<commit_after>class Medium < ActiveRecord::Base
  belongs_to :linked, polymorphic: true

  before_save :create_path, unless: :external_link

  def self.inheritance_column
    nil
  end

  ALLOWED_UPLOAD_CONTENT_TYPES = %w(image/jpeg image/png image/gif)
  ALLOWED_EXPORT_CONTENT_TYPES  = %w(text/csv)

  validate do |medium|
    unless allowed_content_types.include?(medium.content_type)
      medium.errors.add(:content_type, "Content-Type must be one of #{allowed_content_types.join(", ")}")
    end
  end

  def indifferent_attributes
    attributes.dup.with_indifferent_access
  end

  def create_path
    self.src ||= MediaStorage.stored_path(content_type, type, *path_opts)
  end

  def put_url
    if external_link
      src
    else
      MediaStorage.put_path(src, indifferent_attributes)
    end
  end

  def get_url
    if external_link
      src
    else
      MediaStorage.get_path(src, indifferent_attributes)
    end
  end

  def put_file(file_path)
    MediaStorage.put_file(src, file_path, indifferent_attributes)
  end

  def allowed_content_types
    if type == "classifications_export"
      ALLOWED_EXPORT_CONTENT_TYPES
    else
      ALLOWED_UPLOAD_CONTENT_TYPES
    end
  end
end
{'fraction_non_alphanumeric': 0.06858407079646017, 'fraction_numerical': 0.0, 'mean_word_length': 3.7006237006237006, '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': '1736034', 'n_tokens_mistral': 763, 'n_tokens_neox': 740, 'n_words': 162}