diff --git a/app/controllers/react_controller.rb b/app/controllers/react_controller.rb index 56f732dc..24ff71a4 100644 --- a/app/controllers/react_controller.rb +++ b/app/controllers/react_controller.rb @@ -1,10 +1,18 @@ # frozen_string_literal: true class ReactController < ApplicationController + include Authorization + before_action :authenticate_user!, only: [:react, :home] - before_action :set_referrer_policy_header, only: [:react, :home] - before_action :set_initial_state_json, only: [:react, :home] - before_action :set_data_for_meta, only: [:react, :home] + + before_action :set_account, only: [:status_embed, :status_show, :account_show] + before_action :set_status, only: [:status_embed, :status_show] + before_action :check_account_suspension, only: [:status_embed, :status_show, :account_show] + before_action :redirect_to_original, only: [:status_show] + + before_action :set_referrer_policy_header, only: [:react, :home, :status_embed, :status_show, :account_show] + before_action :set_initial_state_json, only: [:react, :home, :status_embed, :status_show, :account_show] + before_action :set_data_for_meta, only: [:react, :home, :status_embed, :status_show, :account_show] before_action :set_instance_presenter @@ -21,8 +29,43 @@ class ReactController < ApplicationController return not_found end + def status_show + return process(:react) + end + + def status_embed + # : todo : + end + + def account_show + # : todo : + end + private + def set_account + @account = Account.find_acct!(params[:username]) + end + + def set_status + @status = @account.statuses.find(params[:statusId]) + + authorize @status, :show? + rescue GabSocial::NotPermittedError + # Reraise in order to get a 404 + raise ActiveRecord::RecordNotFound + end + + def check_account_suspension + gone if @account.suspended? + end + + def redirect_to_original + if @status.reblog? + redirect_to ::TagManager.instance.url_for(@status.reblog) + end + end + def set_data_for_meta return if find_route_matches && current_account @@ -78,6 +121,9 @@ class ReactController < ApplicationController end def set_referrer_policy_header + unless @status.nil? + return if @status.public_visibility? || @status.unlisted_visibility? + end response.headers['Referrer-Policy'] = 'origin' end diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb index e7c19503..861809a0 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account_finder_concern.rb @@ -21,8 +21,7 @@ module AccountFinderConcern end def find_acct(acct) - username, domain = acct.split("@") - find_now(username) + find_now(acct) end def find_now(username) diff --git a/app/views/statuses/_meta.html.haml b/app/views/statuses/_meta.html.haml index 9050b920..2453a281 100644 --- a/app/views/statuses/_meta.html.haml +++ b/app/views/statuses/_meta.html.haml @@ -1,4 +1,4 @@ -- the_title = t('statuses.title', name: display_name(account), quote: truncate(status.spoiler_text.presence || stream_entry.activity.text, length: 50, omission: '…', escape: false)) +- the_title = t('statuses.title', name: display_name(account), quote: truncate(status.spoiler_text.presence, length: 50, omission: '…', escape: false)) - content_for :page_title do = the_title diff --git a/app/views/statuses/_og_description.html.haml b/app/views/statuses/_og_description.html.haml index 70e68e45..05830e7b 100644 --- a/app/views/statuses/_og_description.html.haml +++ b/app/views/statuses/_og_description.html.haml @@ -1,4 +1,4 @@ -- description = t('statuses.title', name: display_name(account), quote: activity.spoiler_text.presence || activity.text) +- description = t('statuses.title', name: display_name(account), quote: status.spoiler_text.presence || status.text) %meta{ name: 'description', content: description }/ = opengraph 'og:description', description diff --git a/app/views/statuses/_og_image.html.haml b/app/views/statuses/_og_image.html.haml index 67f9274b..7337a7e3 100644 --- a/app/views/statuses/_og_image.html.haml +++ b/app/views/statuses/_og_image.html.haml @@ -1,6 +1,6 @@ -- if activity.is_a?(Status) && (activity.non_sensitive_with_media? || (activity.with_media? && Setting.preview_sensitive_media)) +- if status.is_a?(Status) && (status.non_sensitive_with_media? || (status.with_media? && Setting.preview_sensitive_media)) - player_card = false - - activity.media_attachments.each do |media| + - status.media_attachments.each do |media| - if media.image? = opengraph 'og:image', full_asset_url(media.file.url(:original)) = opengraph 'og:image:type', media.file_content_type diff --git a/config/routes.rb b/config/routes.rb index a98b309c..d29f53cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -400,19 +400,18 @@ Rails.application.routes.draw do end end - get '/g/:groupSlug', to: 'react#groupBySlug' + + get '/:username/posts/:statusId', to: 'react#status_show', username: username_regex + get '/:username/posts/:statusId', to: 'react#status_show', username: username_regex, as: :short_account_status + get '/:username/posts/:statusId/embed', to: 'react#embed_status', username: username_regex, as: :embed_short_account_status + get '/(*any)', to: 'react#react', as: :web + get '/:username', to: 'react#account_show', username: username_regex, as: :short_account_with_replies root 'react#react' get '/', to: 'react#react', as: :homepage - get '/:username', to: 'accounts#show', username: username_regex, as: :short_account_with_replies - get '/:username/comments', to: 'accounts#show', username: username_regex, as: :short_account_comments_only - get '/:username/photos', to: 'accounts#show', username: username_regex, as: :short_account_media - get '/:username/posts/:statusId', to: 'statuses#show', username: username_regex - get '/:account_username/posts/:id', to: 'statuses#show', account_username: username_regex, as: :short_account_status - get '/:account_username/posts/:id/embed', to: 'statuses#embed', account_username: username_regex, as: :embed_short_account_status get '/about', to: 'react#react' get '/about/tos', to: 'react#react' get '/about/privacy', to: 'react#react'