diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/api/v1/statuses_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/api_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/auth/registrations_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/media_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/well_known/webfinger_controller.rb | 9 |
5 files changed, 20 insertions, 24 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 1976ce330..b0e26918e 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -77,9 +77,9 @@ class Api::V1::StatusesController < ApiController end def unreblog - reblog = Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first! - @status = reblog.reblog - @reblogged_map = { @status.id => false } + reblog = Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first! + @status = reblog.reblog + @reblogs_map = { @status.id => false } RemovalWorker.perform_async(reblog.id) @@ -93,7 +93,7 @@ class Api::V1::StatusesController < ApiController def unfavourite @status = Status.find(params[:id]) - @favourited_map = { @status.id => false } + @favourites_map = { @status.id => false } UnfavouriteWorker.perform_async(current_user.account_id, @status.id) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 57604f1dc..478d21bc7 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -100,17 +100,4 @@ class ApiController < ApplicationController @reblogs_map = Status.reblogs_map(status_ids, current_account) @favourites_map = Status.favourites_map(status_ids, current_account) end - - def set_counters_maps(statuses) # rubocop:disable Style/AccessorMethodName - status_ids = statuses.compact.map { |s| s.reblog? ? s.reblog_of_id : s.id }.uniq - @favourites_counts_map = Favourite.select('status_id, COUNT(id) AS favourites_count').group('status_id').where(status_id: status_ids).map { |f| [f.status_id, f.favourites_count] }.to_h - @reblogs_counts_map = Status.select('statuses.id, COUNT(reblogs.id) AS reblogs_count').joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.id = reblogs.reblog_of_id').where(id: status_ids).group('statuses.id').map { |r| [r.id, r.reblogs_count] }.to_h - end - - def set_account_counters_maps(accounts) # rubocop:disable Style/AccessorMethodName - account_ids = accounts.compact.map(&:id).uniq - @followers_counts_map = Follow.unscoped.select('target_account_id, COUNT(account_id) AS followers_count').group('target_account_id').where(target_account_id: account_ids).map { |f| [f.target_account_id, f.followers_count] }.to_h - @following_counts_map = Follow.unscoped.select('account_id, COUNT(target_account_id) AS following_count').group('account_id').where(account_id: account_ids).map { |f| [f.account_id, f.following_count] }.to_h - @statuses_counts_map = Status.unscoped.select('account_id, COUNT(id) AS statuses_count').group('account_id').where(account_id: account_ids).map { |s| [s.account_id, s.statuses_count] }.to_h - end end diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index f8050afb5..dd30be32a 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -10,6 +10,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController def build_resource(hash = nil) super(hash) + resource.locale = I18n.locale resource.build_account if resource.account.nil? end diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 488c4f944..fa1daf012 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -1,16 +1,19 @@ # frozen_string_literal: true class MediaController < ApplicationController - before_action :set_media_attachment + before_action :verify_permitted_status def show - redirect_to @media_attachment.file.url(:original) + redirect_to media_attachment.file.url(:original) end private - def set_media_attachment - @media_attachment = MediaAttachment.where.not(status_id: nil).find_by!(shortcode: params[:id]) - raise ActiveRecord::RecordNotFound unless @media_attachment.status.permitted?(current_account) + def media_attachment + MediaAttachment.attached.find_by!(shortcode: params[:id]) + end + + def verify_permitted_status + raise ActiveRecord::RecordNotFound unless media_attachment.status.permitted?(current_account) end end diff --git a/app/controllers/well_known/webfinger_controller.rb b/app/controllers/well_known/webfinger_controller.rb index 1a8ef5f90..4a521d102 100644 --- a/app/controllers/well_known/webfinger_controller.rb +++ b/app/controllers/well_known/webfinger_controller.rb @@ -8,8 +8,13 @@ module WellKnown @magic_key = pem_to_magic_key(@account.keypair.public_key) respond_to do |format| - format.xml { render content_type: 'application/xrd+xml' } - format.json { render content_type: 'application/jrd+json' } + format.any(:json, :html) do + render formats: :json, content_type: 'application/jrd+json' + end + + format.xml do + render content_type: 'application/xrd+xml' + end end rescue ActiveRecord::RecordNotFound head 404 |