Fix some ActivityPub JSON bugs (#4796)
- Fix assumption that `url` is always a string. Handle it if it's an array of strings, array of objects, object, or string, both for accounts and for objects - `sharedInbox` is actually supposed to be under `endpoints`, handle both cases and adjust the serializer
This commit is contained in:
parent
2293466edd
commit
9b50a9dd83
3 changed files with 40 additions and 8 deletions
|
@ -6,7 +6,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
# Should be called with confirmed valid JSON
|
||||
# and WebFinger-resolved username and domain
|
||||
def call(username, domain, json)
|
||||
return unless json['inbox'].present?
|
||||
return if json['inbox'].blank?
|
||||
|
||||
@json = json
|
||||
@uri = @json['id']
|
||||
|
@ -42,9 +42,9 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
@account.protocol = :activitypub
|
||||
@account.inbox_url = @json['inbox'] || ''
|
||||
@account.outbox_url = @json['outbox'] || ''
|
||||
@account.shared_inbox_url = @json['sharedInbox'] || ''
|
||||
@account.shared_inbox_url = (@json['endpoints'].is_a?(Hash) ? @json['endpoints']['sharedInbox'] : @json['sharedInbox']) || ''
|
||||
@account.followers_url = @json['followers'] || ''
|
||||
@account.url = @json['url'] || @uri
|
||||
@account.url = url || @uri
|
||||
@account.display_name = @json['name'] || ''
|
||||
@account.note = @json['summary'] || ''
|
||||
@account.avatar_remote_url = image_url('icon')
|
||||
|
@ -62,7 +62,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
value = first_of_value(@json[key])
|
||||
|
||||
return if value.nil?
|
||||
return @json[key]['url'] if @json[key].is_a?(Hash)
|
||||
return value['url'] if value.is_a?(Hash)
|
||||
|
||||
image = fetch_resource(value)
|
||||
image['url'] if image
|
||||
|
@ -78,6 +78,16 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
key['publicKeyPem'] if key
|
||||
end
|
||||
|
||||
def url
|
||||
return if @json['url'].blank?
|
||||
|
||||
value = first_of_value(@json['url'])
|
||||
|
||||
return value if value.is_a?(String)
|
||||
|
||||
value['href']
|
||||
end
|
||||
|
||||
def auto_suspend?
|
||||
domain_block && domain_block.suspend?
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue