Class: Alchemy::StorageAdapter::ActiveStorage::SanitizeSvgJob

Inherits:
BaseJob
  • Object
show all
Defined in:
app/jobs/alchemy/storage_adapter/active_storage/sanitize_svg_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(attachable, file_accessor: :image_file) ⇒ Object

Parameters:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/alchemy/storage_adapter/active_storage/sanitize_svg_job.rb', line 10

def perform(attachable, file_accessor: :image_file)
  return unless attachable.svg?

  blob = attachable.send(file_accessor).blob
  return if blob.[:sanitized]

  sanitized = sanitize(blob.download)

  Tempfile.create([blob.filename.base, blob.filename.extension]) do |file|
    file.puts(sanitized)
    file.rewind
    blob.upload(file)
  end

  blob.[:sanitized] = true
  blob.save!
end