<commit_before>require 'dragonfly'
require 'rack/cache'

datastore = Dragonfly::DataStorage::S3DataStore.new(
  :bucket_name => ENV['S3_BUCKET'],
  :access_key_id => ENV['S3_KEY'],
  :secret_access_key => ENV['S3_SECRET']
)

# Image store
app = Dragonfly[:images]
app.configure_with(:imagemagick)
app.configure_with(:rails)

app.content_filename = proc do |job, request|
  if job.process_steps.any?
    "#{job.basename}_#{job.process_steps.first.name}.#{job.format}"
  else
    "#{job.basename}.#{job.format}"
  end
end

if ENV['S3_ENABLED']
  app.configure do |c|
    c.datastore = datastore
    c.protect_from_dos_attacks = false
    c.secret = ENV['DRAGONFLY_SECRET']
    c.url_format = "/media/:job/:basename.:format"
  end
else
  app.configure do |c|
    c.url_format = "/media/:job/:basename.:format"
  end
end

app.define_macro(ActiveRecord::Base, :image_accessor)

if !Rails.env.test? && defined?(Rack::Cache)<commit_msg>Enable DOS protection<commit_after>require 'dragonfly'
require 'rack/cache'

datastore = Dragonfly::DataStorage::S3DataStore.new(
  :bucket_name => ENV['S3_BUCKET'],
  :access_key_id => ENV['S3_KEY'],
  :secret_access_key => ENV['S3_SECRET']
)

# Image store
app = Dragonfly[:images]
app.configure_with(:imagemagick)
app.configure_with(:rails)

app.content_filename = proc do |job, request|
  if job.process_steps.any?
    "#{job.basename}_#{job.process_steps.first.name}.#{job.format}"
  else
    "#{job.basename}.#{job.format}"
  end
end

if ENV['S3_ENABLED']
  app.configure do |c|
    c.datastore = datastore
    c.protect_from_dos_attacks = true
    c.secret = ENV['DRAGONFLY_SECRET']
    c.url_format = "/media/:job/:basename.:format"
  end
else
  app.configure do |c|
    c.url_format = "/media/:job/:basename.:format"
  end
end

app.define_macro(ActiveRecord::Base, :image_accessor)

if !Rails.env.test? && defined?(Rack::Cache)
{'fraction_non_alphanumeric': 0.15871313672922252, 'fraction_numerical': 0.005361930294906166, 'mean_word_length': 4.849529780564263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4018141', 'n_tokens_mistral': 730, 'n_tokens_neox': 743, 'n_words': 115}