闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. require 'csv'
  3. class ImportWorker
  4. include Sidekiq::Worker
  5. sidekiq_options queue: 'pull', retry: false
  6. def perform(import_id)
  7. import = Import.find(import_id)
  8. case import.type
  9. when 'blocking'
  10. process_blocks(import)
  11. when 'following'
  12. process_follows(import)
  13. end
  14. import.destroy
  15. end
  16. private
  17. def process_blocks(import)
  18. from_account = import.account
  19. CSV.new(open(import.data.url)).each do |row|
  20. next if row.size != 1
  21. begin
  22. target_account = FollowRemoteAccountService.new.call(row[0])
  23. next if target_account.nil?
  24. BlockService.new.call(from_account, target_account)
  25. rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError
  26. next
  27. end
  28. end
  29. end
  30. def process_follows(import)
  31. from_account = import.account
  32. CSV.new(open(import.data.url)).each do |row|
  33. next if row.size != 1
  34. begin
  35. FollowService.new.call(from_account, row[0])
  36. rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError
  37. next
  38. end
  39. end
  40. end
  41. end