mirror of
https://github.com/mastodon/mastodon.git
synced 2026-05-12 23:23:01 -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
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
JavaScript Testing / test (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
64 lines
1.6 KiB
Ruby
64 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1Alpha::InCollectionsController < Api::BaseController
|
|
include Authorization
|
|
|
|
DEFAULT_COLLECTIONS_LIMIT = 40
|
|
|
|
before_action :check_feature_enabled
|
|
|
|
before_action -> { authorize_if_got_token! :read, :'read:collections' }, only: [:index]
|
|
|
|
before_action :require_user!
|
|
before_action :set_account, only: [:index]
|
|
before_action :set_collections, only: [:index]
|
|
|
|
after_action :insert_pagination_headers, only: [:index]
|
|
|
|
after_action :verify_authorized
|
|
|
|
def index
|
|
cache_if_unauthenticated!
|
|
authorize @account, :index_featured_in_collections?
|
|
|
|
render json: @collections, each_serializer: REST::CollectionSerializer, adapter: :json
|
|
end
|
|
|
|
private
|
|
|
|
def set_account
|
|
@account = Account.find(params[:account_id])
|
|
end
|
|
|
|
def set_collections
|
|
@collections = @account.featured_in_collections
|
|
.with_tag
|
|
.offset(offset_param)
|
|
.limit(limit_param(DEFAULT_COLLECTIONS_LIMIT))
|
|
end
|
|
|
|
def check_feature_enabled
|
|
raise ActionController::RoutingError unless Mastodon::Feature.collections_enabled?
|
|
end
|
|
|
|
def next_path
|
|
return unless records_continue?
|
|
|
|
api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT)))
|
|
end
|
|
|
|
def prev_path
|
|
return if offset_param.zero?
|
|
|
|
api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT)))
|
|
end
|
|
|
|
def records_continue?
|
|
((offset_param * limit_param(DEFAULT_COLLECTIONS_LIMIT)) + @collections.size) < @account.featured_in_collections.size
|
|
end
|
|
|
|
def offset_param
|
|
params[:offset].to_i
|
|
end
|
|
end
|