follows_controller.rb 732 B

12345678910111213141516171819202122232425262728293031
  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