home_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. class HomeController < ApplicationController
  3. before_action :authenticate_user!
  4. before_action :set_referrer_policy_header
  5. def index
  6. @body_classes = 'app-body'
  7. end
  8. private
  9. def authenticate_user!
  10. return if user_signed_in?
  11. matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
  12. if matches
  13. case matches[1]
  14. when 'statuses'
  15. status = Status.find_by(id: matches[2])
  16. if status&.distributable?
  17. redirect_to(ActivityPub::TagManager.instance.url_for(status))
  18. return
  19. end
  20. when 'accounts'
  21. account = Account.find_by(id: matches[2])
  22. if account
  23. redirect_to(ActivityPub::TagManager.instance.url_for(account))
  24. return
  25. end
  26. end
  27. end
  28. matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
  29. redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
  30. end
  31. def default_redirect_path
  32. if request.path.start_with?('/web') || whitelist_mode?
  33. new_user_session_path
  34. elsif single_user_mode?
  35. short_account_path(Account.local.without_suspended.where('id > 0').first)
  36. else
  37. about_path
  38. end
  39. end
  40. def set_referrer_policy_header
  41. response.headers['Referrer-Policy'] = 'origin'
  42. end
  43. end