logo

mastofe

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

status_finder.rb (696B)


  1. # frozen_string_literal: true
  2. class StatusFinder
  3. attr_reader :url
  4. def initialize(url)
  5. @url = url
  6. end
  7. def status
  8. verify_action!
  9. raise ActiveRecord::RecordNotFound unless TagManager.instance.local_url?(url)
  10. case recognized_params[:controller]
  11. when 'stream_entries'
  12. StreamEntry.find(recognized_params[:id]).status
  13. when 'statuses'
  14. Status.find(recognized_params[:id])
  15. else
  16. raise ActiveRecord::RecordNotFound
  17. end
  18. end
  19. private
  20. def recognized_params
  21. Rails.application.routes.recognize_path(url)
  22. end
  23. def verify_action!
  24. unless recognized_params[:action] == 'show'
  25. raise ActiveRecord::RecordNotFound
  26. end
  27. end
  28. end