translations_controller.rb 858 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::TranslationsController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :read, :'read:statuses' }
  5. before_action :set_status
  6. before_action :set_translation
  7. rescue_from TranslationService::NotConfiguredError, with: :not_found
  8. rescue_from TranslationService::UnexpectedResponseError, TranslationService::QuotaExceededError, TranslationService::TooManyRequestsError, with: :service_unavailable
  9. def create
  10. render json: @translation, serializer: REST::TranslationSerializer
  11. end
  12. private
  13. def set_status
  14. @status = Status.find(params[:status_id])
  15. authorize @status, :show?
  16. rescue Mastodon::NotPermittedError
  17. not_found
  18. end
  19. def set_translation
  20. @translation = TranslateStatusService.new.call(@status, content_locale)
  21. end
  22. end