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.

47 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class RemoteFollowController < ApplicationController
  3. layout 'public'
  4. before_action :set_account
  5. before_action :check_account_suspension
  6. def new
  7. @remote_follow = RemoteFollow.new
  8. end
  9. def create
  10. @remote_follow = RemoteFollow.new(resource_params)
  11. if @remote_follow.valid?
  12. resource = Goldfinger.finger("acct:#{@remote_follow.acct}")
  13. redirect_url_link = resource&.link('http://ostatus.org/schema/1.0/subscribe')
  14. if redirect_url_link.nil? || redirect_url_link.template.nil?
  15. @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
  16. render(:new) && return
  17. end
  18. redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: "#{@account.username}@#{Rails.configuration.x.local_domain}").to_s
  19. else
  20. render :new
  21. end
  22. rescue Goldfinger::Error
  23. @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
  24. render :new
  25. end
  26. private
  27. def resource_params
  28. params.require(:remote_follow).permit(:acct)
  29. end
  30. def set_account
  31. @account = Account.find_local!(params[:account_username])
  32. end
  33. def check_account_suspension
  34. head 410 if @account.suspended?
  35. end
  36. end