闭社主体 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.

19 lines
663 B

  1. # frozen_string_literal: true
  2. module Payloadable
  3. def serialize_payload(record, serializer, options = {})
  4. signer = options.delete(:signer)
  5. sign_with = options.delete(:sign_with)
  6. payload = ActiveModelSerializers::SerializableResource.new(record, options.merge(serializer: serializer, adapter: ActivityPub::Adapter)).as_json
  7. if (record.respond_to?(:sign?) && record.sign?) && signer && signing_enabled?
  8. ActivityPub::LinkedDataSignature.new(payload).sign!(signer, sign_with: sign_with)
  9. else
  10. payload
  11. end
  12. end
  13. def signing_enabled?
  14. ENV['AUTHORIZED_FETCH'] != 'true' && !Rails.configuration.x.whitelist_mode
  15. end
  16. end