Skip to content

Commit

Permalink
Refactor incoming avatar/header alt text handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEssem committed Dec 17, 2024
1 parent bdc093d commit 29d01f5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/services/activitypub/process_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,31 @@ def actor_type
end
end

def image_url(key)
def image(key)
value = first_of_value(@json[key])

return if value.nil?

if value.is_a?(String)
value = fetch_resource_without_id_validation(value)
return if value.nil?
nil if value.nil?
end
end

def image_url(key)
value = image(key)

value = first_of_value(value['url']) if value.is_a?(Hash) && value['type'] == 'Image'
value = value['href'] if value.is_a?(Hash)
value if value.is_a?(String)
end

def image_description(key)
value = first_of_value(@json[key])
value = image(key)

return if value.nil? || value.is_a?(String)
return unless value.is_a?(Hash)

value = first_of_value(value['summary']) || first_of_value(value['name']) if value.is_a?(Hash) && value['type'] == 'Image'
value = first_of_value(value['summary']) || first_of_value(value['name']) if value['type'] == 'Image'
value if value.is_a?(String)
end

Expand Down

0 comments on commit 29d01f5

Please sign in to comment.