2023-02-23 09:08:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2023-02-24 05:53:43 -05:00
|
|
|
class EvaluatePostUploads < ::Jobs::Base
|
2023-02-23 09:08:34 -05:00
|
|
|
def execute(args)
|
2023-02-24 07:11:58 -05:00
|
|
|
return unless SiteSetting.ai_nsfw_detection_enabled
|
|
|
|
return if (post_id = args[:post_id]).blank?
|
2023-02-23 09:08:34 -05:00
|
|
|
|
2023-02-24 07:11:58 -05:00
|
|
|
post = Post.includes(:uploads).find_by_id(post_id)
|
|
|
|
return if post.nil? || post.uploads.empty?
|
2023-02-23 09:08:34 -05:00
|
|
|
|
2023-02-24 11:25:02 -05:00
|
|
|
return if post.uploads.none? { |u| FileHelper.is_supported_image?(u.url) }
|
2023-02-23 09:08:34 -05:00
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
DiscourseAi::PostClassificator.new(DiscourseAi::NSFW::NSFWClassification.new).classify!(post)
|
2023-02-23 09:08:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|