1
0

home_controller.rb 1.4 KB

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