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.

53 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::InboxesController < Api::BaseController
  3. include SignatureVerification
  4. include JsonLdHelper
  5. before_action :set_account
  6. def create
  7. if unknown_deleted_account?
  8. head 202
  9. elsif signed_request_account
  10. upgrade_account
  11. process_payload
  12. head 202
  13. else
  14. render plain: signature_verification_failure_reason, status: 401
  15. end
  16. end
  17. private
  18. def unknown_deleted_account?
  19. json = Oj.load(body, mode: :strict)
  20. json['type'] == 'Delete' && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists?
  21. rescue Oj::ParseError
  22. false
  23. end
  24. def set_account
  25. @account = Account.find_local!(params[:account_username]) if params[:account_username]
  26. end
  27. def body
  28. return @body if defined?(@body)
  29. @body = request.body.read.force_encoding('UTF-8')
  30. request.body.rewind if request.body.respond_to?(:rewind)
  31. @body
  32. end
  33. def upgrade_account
  34. if signed_request_account.ostatus?
  35. signed_request_account.update(last_webfingered_at: nil)
  36. ResolveAccountWorker.perform_async(signed_request_account.acct)
  37. end
  38. DeliveryFailureTracker.track_inverse_success!(signed_request_account)
  39. end
  40. def process_payload
  41. ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body, @account&.id)
  42. end
  43. end