module Clacky::Utils::FileProcessor

def self.save_image_to_disk(body:, mime_type:, filename: "image.jpg")

Used by agent when an image exceeds MAX_IMAGE_BYTES and must be downgraded to disk.
Save raw image bytes to disk and return a FileRef.
def self.save_image_to_disk(body:, mime_type:, filename: "image.jpg")
  FileUtils.mkdir_p(UPLOAD_DIR)
  safe_name = sanitize_filename(filename)
  dest      = File.join(UPLOAD_DIR, "#{SecureRandom.hex(8)}_#{safe_name}")
  File.binwrite(dest, body)
  FileRef.new(name: safe_name, type: :image, original_path: dest)
end