<commit_before>class ProjectFile < ActiveRecord::Base
  belongs_to :project
  belongs_to :uploader, class_name: "User"

  after_destroy :delete_s3_file
  
  private
  def delete_s3_file
    s3 = Fog::Storage.new(provider: "AWS", aws_access_key_id: S3DirectUpload.config.access_key_id, aws_secret_access_key: S3DirectUpload.config.secret_access_key)
    bucket = s3.directories.get(S3DirectUpload.config.bucket)
    file = bucket.files.get(s3_key)
    file.destroy
  end
  
  def s3_key
    CGI.unescape(filepath.gsub(%r(\A/#{S3DirectUpload.config.bucket}/), ''))
  end
end<commit_msg>Fix weird escaping coming from JS plugin<commit_after>class ProjectFile < ActiveRecord::Base
  belongs_to :project
  belongs_to :uploader, class_name: "User"

  after_destroy :delete_s3_file
  
  def filepath=(filepath)
    write_attribute :filepath, CGI.unescape(filepath)
  end
  
  def url=(url)
    write_attribute :url, CGI.unescape(url)
  end
  
  private
  def delete_s3_file
    s3 = Fog::Storage.new(provider: "AWS", aws_access_key_id: S3DirectUpload.config.access_key_id, aws_secret_access_key: S3DirectUpload.config.secret_access_key)
    bucket = s3.directories.get(S3DirectUpload.config.bucket)
    file = bucket.files.get(s3_key)
    file.destroy
  end
  
  def s3_key
    filepath.gsub(%r(\A/#{S3DirectUpload.config.bucket}/), '')
  end
end
{'fraction_non_alphanumeric': 0.10380881254667662, 'fraction_numerical': 0.014936519790888723, 'mean_word_length': 4.630252100840337, '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': '4707979', 'n_tokens_mistral': 491, 'n_tokens_neox': 498, 'n_words': 81}