1 # frozen_string_literal: true
3 class HomeController
< ApplicationController
4 before_action
:authenticate_user!
5 before_action
:set_referrer_policy_header
6 before_action
:set_initial_state_json
9 @body_classes = 'app-body'
14 def authenticate_user!
15 return if user_signed_in
?
17 matches
= request
.path
.match(/\A\/web\
/(statuses|accounts)\/([\d
]+
)\z
/)
22 status
= Status
.find_by(id
: matches
[2])
24 if status
&.distributable
?
25 redirect_to(ActivityPub
::TagManager.instance
.url_for(status
))
29 account
= Account
.find_by(id
: matches
[2])
32 redirect_to(ActivityPub
::TagManager.instance
.url_for(account
))
38 matches
= request
.path
.match(%r
{\A
/web/timelines
/tag/(?<tag
>.+
)\z
})
39 redirect_to(matches
? tag_path(CGI
.unescape(matches
[:tag])) : default_redirect_path
)
42 def set_initial_state_json
43 serializable_resource
= ActiveModelSerializers
::SerializableResource.new(InitialStatePresenter
.new(initial_state_params
), serializer
: InitialStateSerializer
)
44 @initial_state_json = serializable_resource
.to_json
47 def initial_state_params
49 settings
: Web
::Setting.find_by(user
: current_user
)&.data || {},
50 push_subscription
: current_account
.user
.web_push_subscription(current_session
),
51 current_account
: current_account
,
52 token
: current_session
.token
,
53 admin
: Account
.find_local(Setting
.site_contact_username
.strip
.gsub(/\A@/, '')),
57 def default_redirect_path
58 if request
.path
.start_with
?('/web') || whitelist_mode
?
60 elsif single_user_mode
?
61 short_account_path(Account
.local
.without_suspended
.where('id > 0').first
)
67 def set_referrer_policy_header
68 response
.headers
['Referrer-Policy'] = 'origin'