Class: Jobs::PullUserProfileHotlinkedImages
- Inherits:
-
PullHotlinkedImages
- Object
- Base
- PullHotlinkedImages
- Jobs::PullUserProfileHotlinkedImages
- Defined in:
- app/jobs/regular/pull_user_profile_hotlinked_images.rb
Instance Method Summary collapse
Methods inherited from PullHotlinkedImages
#attempt_download, #download, #extract_images_from, #log, #pull_hotlinked_images, #should_download_image?
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Instance Method Details
#execute(args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/jobs/regular/pull_user_profile_hotlinked_images.rb', line 5 def execute(args) @user_id = args[:user_id] raise Discourse::InvalidParameters.new(:user_id) if @user_id.blank? user_profile = UserProfile.find_by(user_id: @user_id) return if user_profile.blank? || user_profile.bio_cooked.nil? large_image_urls = [] broken_image_urls = [] downloaded_images = {} extract_images_from(user_profile.bio_cooked).each do |node| download_src = original_src = node["src"] || node["href"] download_src = "#{SiteSetting.force_https ? "https" : "http"}:#{original_src}" if original_src.start_with?( "//", ) normalized_src = normalize_src(download_src) next if !should_download_image?(download_src) begin already_attempted_download = downloaded_images.include?(normalized_src) || large_image_urls.include?(normalized_src) || broken_image_urls.include?(normalized_src) if !already_attempted_download downloaded_images[normalized_src] = attempt_download(download_src, @user_id) end rescue ImageTooLargeError large_image_urls << normalized_src rescue ImageBrokenError broken_image_urls << normalized_src end rescue => e raise e if Rails.env.test? log( :error, "Failed to pull hotlinked image (#{download_src}) user: #{@user_id}\n" + e. + "\n" + e.backtrace.join("\n"), ) end user_profile.bio_raw = InlineUploads.replace_hotlinked_image_urls(raw: user_profile.bio_raw) do |match_src| normalized_match_src = PostHotlinkedMedia.normalize_src(match_src) downloaded_images[normalized_match_src] end user_profile.skip_pull_hotlinked_image = true user_profile.save! end |