mirror of
https://github.com/mastodon/mastodon.git
synced 2026-06-11 02:00:48 -05:00
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / test (3.4) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.4) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
54 lines
1.6 KiB
Ruby
54 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CollectionsController < ApplicationController
|
|
include WebAppControllerConcern
|
|
include SignatureAuthentication
|
|
include Authorization
|
|
include AccountOwnedConcern
|
|
|
|
vary_by -> { public_fetch_mode? ? 'Accept, Accept-Language, Cookie' : 'Accept, Accept-Language, Cookie, Signature' }
|
|
|
|
before_action :require_account_signature!, only: :show, if: -> { request.format == :json && authorized_fetch_mode? }
|
|
before_action :set_collection
|
|
|
|
skip_around_action :set_locale, if: -> { request.format == :json }
|
|
skip_before_action :require_functional!, only: :show, unless: :limited_federation_mode?
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.html do
|
|
expires_in expiration_duration, public: true unless user_signed_in?
|
|
render template: 'home/index'
|
|
end
|
|
|
|
format.json do
|
|
expires_in expiration_duration, public: true if public_fetch_mode?
|
|
render_with_cache json: @collection, content_type: 'application/activity+json', serializer: ActivityPub::FeaturedCollectionSerializer, adapter: ActivityPub::Adapter
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_account
|
|
if account_id_param.present?
|
|
@account = Account.local.find(account_id_param)
|
|
else
|
|
@collection = Collection.find(params[:id])
|
|
@account = @collection.account
|
|
end
|
|
end
|
|
|
|
def set_collection
|
|
@collection ||= @account.collections.find(params[:id])
|
|
authorize @collection, :show?
|
|
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
|
|
not_found
|
|
end
|
|
|
|
def expiration_duration
|
|
recently_updated = @collection.updated_at > 15.minutes.ago
|
|
recently_updated ? 30.seconds : 5.minutes
|
|
end
|
|
end
|