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.

61 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class AuthorizeFollowsController < ApplicationController
  3. layout 'public'
  4. before_action :authenticate_user!
  5. def show
  6. @account = located_account || render(:error)
  7. end
  8. def create
  9. @account = follow_attempt.try(:target_account)
  10. if @account.nil?
  11. render :error
  12. else
  13. redirect_to web_url("accounts/#{@account.id}")
  14. end
  15. rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
  16. render :error
  17. end
  18. private
  19. def follow_attempt
  20. FollowService.new.call(current_account, acct_without_prefix)
  21. end
  22. def located_account
  23. if acct_param_is_url?
  24. account_from_remote_fetch
  25. else
  26. account_from_remote_follow
  27. end
  28. end
  29. def account_from_remote_fetch
  30. FetchRemoteAccountService.new.call(acct_without_prefix)
  31. end
  32. def account_from_remote_follow
  33. ResolveRemoteAccountService.new.call(acct_without_prefix)
  34. end
  35. def acct_param_is_url?
  36. parsed_uri.path && %w(http https).include?(parsed_uri.scheme)
  37. end
  38. def parsed_uri
  39. Addressable::URI.parse(acct_without_prefix).normalize
  40. end
  41. def acct_without_prefix
  42. acct_params.gsub(/\Aacct:/, '')
  43. end
  44. def acct_params
  45. params.fetch(:acct, '')
  46. end
  47. end