logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

domain_blocks_controller.rb (1540B)


  1. # frozen_string_literal: true
  2. class Api::V1::DomainBlocksController < Api::BaseController
  3. BLOCK_LIMIT = 100
  4. before_action -> { doorkeeper_authorize! :follow }
  5. before_action :require_user!
  6. after_action :insert_pagination_headers, only: :show
  7. respond_to :json
  8. def show
  9. @blocks = load_domain_blocks
  10. render json: @blocks.map(&:domain)
  11. end
  12. def create
  13. BlockDomainFromAccountService.new.call(current_account, domain_block_params[:domain])
  14. render_empty
  15. end
  16. def destroy
  17. current_account.unblock_domain!(domain_block_params[:domain])
  18. render_empty
  19. end
  20. private
  21. def load_domain_blocks
  22. account_domain_blocks.paginate_by_max_id(
  23. limit_param(BLOCK_LIMIT),
  24. params[:max_id],
  25. params[:since_id]
  26. )
  27. end
  28. def account_domain_blocks
  29. current_account.domain_blocks
  30. end
  31. def insert_pagination_headers
  32. set_pagination_headers(next_path, prev_path)
  33. end
  34. def next_path
  35. if records_continue?
  36. api_v1_domain_blocks_url pagination_params(max_id: pagination_max_id)
  37. end
  38. end
  39. def prev_path
  40. unless @blocks.empty?
  41. api_v1_domain_blocks_url pagination_params(since_id: pagination_since_id)
  42. end
  43. end
  44. def pagination_max_id
  45. @blocks.last.id
  46. end
  47. def pagination_since_id
  48. @blocks.first.id
  49. end
  50. def records_continue?
  51. @blocks.size == limit_param(BLOCK_LIMIT)
  52. end
  53. def pagination_params(core_params)
  54. params.slice(:limit).permit(:limit).merge(core_params)
  55. end
  56. def domain_block_params
  57. params.permit(:domain)
  58. end
  59. end