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.

31 lines
732 B

  1. # frozen_string_literal: true
  2. class Api::V1::FollowsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :follow, :'write:follows' }
  4. before_action :require_user!
  5. respond_to :json
  6. def create
  7. raise ActiveRecord::RecordNotFound if follow_params[:uri].blank?
  8. @account = FollowService.new.call(current_user.account, target_uri).try(:target_account)
  9. if @account.nil?
  10. username, domain = target_uri.split('@')
  11. @account = Account.find_remote!(username, domain)
  12. end
  13. render json: @account, serializer: REST::AccountSerializer
  14. end
  15. private
  16. def target_uri
  17. follow_params[:uri].strip.gsub(/\A@/, '')
  18. end
  19. def follow_params
  20. params.permit(:uri)
  21. end
  22. end