The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

33 linhas
867 B

  1. # frozen_string_literal: true
  2. class VerifyLinkService < BaseService
  3. def call(field)
  4. @link_back = ActivityPub::TagManager.instance.url_for(field.account)
  5. @url = field.value
  6. perform_request!
  7. return unless link_back_present?
  8. field.mark_verified!
  9. field.account.save!
  10. rescue HTTP::Error, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
  11. Rails.logger.debug "Error fetching link #{@url}: #{e}"
  12. nil
  13. end
  14. private
  15. def perform_request!
  16. @body = Request.new(:get, @url).add_headers('Accept' => 'text/html').perform do |res|
  17. res.code != 200 ? nil : res.body_with_limit
  18. end
  19. end
  20. def link_back_present?
  21. return false if @body.empty?
  22. Nokogiri::HTML(@body).xpath('//a[@rel="me"]|//link[@rel="me"]').any? { |link| link['href'] == @link_back }
  23. end
  24. end