Class: RailsImagePostSolution::ImageModerationJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/rails_image_post_solution/image_moderation_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(attachment_id) ⇒ Object

Job to perform automatic image moderation Uses OpenAI Vision API to detect R18/R18G content



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/rails_image_post_solution/image_moderation_job.rb', line 9

def perform(attachment_id)
  attachment = ActiveStorage::Attachment.find_by(id: attachment_id)
  return unless attachment&.blob

  # Analyze image using OpenAI Vision Service
  result = OpenaiVisionService.new.moderate_image(attachment)

  # Process results
  if result[:flagged]
    # Create automatic report when inappropriate content is detected
    create_auto_report(attachment, result)

    # Temporarily freeze post (if enabled in config)
    freeze_post(attachment, result) if auto_freeze_enabled?
  end

  Rails.logger.info "Image moderation completed for attachment ##{attachment_id}: #{result[:flagged] ? 'FLAGGED' : 'OK'}"
rescue StandardError => e
  Rails.logger.error "Image moderation failed for attachment ##{attachment_id}: #{e.message}"
  # Don't fail the job on error (leave for manual review)
end