You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

7 years ago
7 years ago
7 years ago
  1. # frozen_string_literal: true
  2. class TagsController < ApplicationController
  3. include SignatureVerification
  4. include WebAppControllerConcern
  5. PAGE_SIZE = 20
  6. PAGE_SIZE_MAX = 200
  7. before_action :require_account_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
  8. before_action :authenticate_user!, if: :whitelist_mode?
  9. before_action :set_local
  10. before_action :set_tag
  11. before_action :set_statuses, if: -> { request.format == :rss }
  12. before_action :set_instance_presenter
  13. skip_before_action :require_functional!, unless: :whitelist_mode?
  14. def show
  15. respond_to do |format|
  16. format.html do
  17. expires_in 0, public: true unless user_signed_in?
  18. end
  19. format.rss do
  20. expires_in 0, public: true
  21. end
  22. format.json do
  23. expires_in 3.minutes, public: public_fetch_mode?
  24. render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
  25. end
  26. end
  27. end
  28. private
  29. def set_tag
  30. @tag = Tag.usable.find_normalized!(params[:id])
  31. end
  32. def set_local
  33. @local = truthy_param?(:local)
  34. end
  35. def set_statuses
  36. @statuses = cache_collection(TagFeed.new(@tag, nil, local: @local).get(limit_param), Status)
  37. end
  38. def set_instance_presenter
  39. @instance_presenter = InstancePresenter.new
  40. end
  41. def limit_param
  42. params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
  43. end
  44. def collection_presenter
  45. ActivityPub::CollectionPresenter.new(
  46. id: tag_url(@tag),
  47. type: :ordered
  48. )
  49. end
  50. end