<commit_before>class Admin::RestoreImagesJob
  include Sidekiq::Job

  def perform(name)
    puts "starting: #{name}"
    @client = Azure::Storage::Blob::BlobService.create(
      storage_account_name: ENV.fetch('AZURE_STORAGE_ACCOUNT'),
      storage_access_key: ENV.fetch('AZURE_STORAGE_KEY'))

    # Extract separate parts
    collection_ref, folder, filename = name.split('/')

    # Get file data
    data = @client.get_blob('uploadedfiles', name)[1]

    # Create a temporary file
    Tempfile.create('tmpfile') do |temp|
      
      # Fix the file data and save to temp file
      File.binwrite(temp, Base64.decode64(data).force_encoding('utf-8'))

      # Upload new file
      uploader = DocumentUpload.new(temp, document_key: folder, filename: "restored_#{filename}", content_type: MimeMagic.by_path(name).try(:type),
    collection_ref: collection_ref)

      uploader.upload! if uploader.valid?
      # sleep(1)

      raise UploadError.new(uploader.errors) if uploader.errors?
      puts "finished: #{name}"
    end
  end
end
<commit_msg>Dev fix rubocop restore images issue (#909)<commit_after>class Admin::RestoreImagesJob
  include Sidekiq::Job

  def perform(name)
    puts "starting: #{name}"
    @client = Azure::Storage::Blob::BlobService.create(
      storage_account_name: ENV.fetch('AZURE_STORAGE_ACCOUNT'),
      storage_access_key: ENV.fetch('AZURE_STORAGE_KEY')
    )

    # Extract separate parts
    collection_ref, folder, filename = name.split('/')

    # Get file data
    data = @client.get_blob('uploadedfiles', name)[1]

    # Create a temporary file
    Tempfile.create('tmpfile') do |temp|
      # Fix the file data and save to temp file
      File.binwrite(temp, Base64.decode64(data).force_encoding('utf-8'))

      # Upload new file
      uploader = DocumentUpload.new(temp, document_key: folder, filename: "restored_#{filename}", content_type: MimeMagic.by_path(name).try(:type),
    collection_ref: collection_ref)

      uploader.upload! if uploader.valid?
      # sleep(1)


      raise UploadError, uploader.errors if uploader.errors?
      puts "finished: #{name}"
    end
  end
end

{'fraction_non_alphanumeric': 0.11883513386566463, 'fraction_numerical': 0.007984969469234382, 'mean_word_length': 3.7333333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4540262', 'n_tokens_mistral': 693, 'n_tokens_neox': 665, 'n_words': 153}