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

50 lines
1.3 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. @remote_follow.acct = session[:remote_follow] if session.key?(:remote_follow)
  9. end
  10. def create
  11. @remote_follow = RemoteFollow.new(resource_params)
  12. if @remote_follow.valid?
  13. resource = Goldfinger.finger("acct:#{@remote_follow.acct}")
  14. redirect_url_link = resource&.link('http://ostatus.org/schema/1.0/subscribe')
  15. if redirect_url_link.nil? || redirect_url_link.template.nil?
  16. @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
  17. render(:new) && return
  18. end
  19. session[:remote_follow] = @remote_follow.acct
  20. redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: @account.to_webfinger_s).to_s
  21. else
  22. render :new
  23. end
  24. rescue Goldfinger::Error
  25. @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
  26. render :new
  27. end
  28. private
  29. def resource_params
  30. params.require(:remote_follow).permit(:acct)
  31. end
  32. def set_account
  33. @account = Account.find_local!(params[:account_username])
  34. end
  35. def check_account_suspension
  36. head 410 if @account.suspended?
  37. end
  38. end