2022-09-24 07:00:12 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Statuses::TranslationsController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
before_action -> { doorkeeper_authorize! :read, :'read:statuses' }
|
2024-07-05 00:26:49 +10:00
|
|
|
before_action :require_user!
|
2022-09-24 07:00:12 +10:00
|
|
|
before_action :set_status
|
|
|
|
before_action :set_translation
|
|
|
|
|
|
|
|
rescue_from TranslationService::NotConfiguredError, with: :not_found
|
2023-08-29 17:14:44 +10:00
|
|
|
rescue_from TranslationService::UnexpectedResponseError, with: :service_unavailable
|
|
|
|
|
|
|
|
rescue_from TranslationService::QuotaExceededError do
|
|
|
|
render json: { error: I18n.t('translation.errors.quota_exceeded') }, status: 503
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from TranslationService::TooManyRequestsError do
|
|
|
|
render json: { error: I18n.t('translation.errors.too_many_requests') }, status: 503
|
|
|
|
end
|
2022-09-24 07:00:12 +10:00
|
|
|
|
|
|
|
def create
|
|
|
|
render json: @translation, serializer: REST::TranslationSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_status
|
|
|
|
@status = Status.find(params[:status_id])
|
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_translation
|
|
|
|
@translation = TranslateStatusService.new.call(@status, content_locale)
|
|
|
|
end
|
|
|
|
end
|