diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-09-23 23:00:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-23 23:00:12 +0200 |
commit | 0d6b878808a02aa4a544e894f06419c0f612c163 (patch) | |
tree | 119723ea46dd8525c370fee1235c3c9d42e55937 /app/controllers/api | |
parent | d2f7e30a283a1dca1f7974884ac0c237b93903ad (diff) |
Add user content translations with configurable backends (#19218)
Diffstat (limited to 'app/controllers/api')
-rw-r--r-- | app/controllers/api/v1/statuses/translations_controller.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/api/v1/statuses/translations_controller.rb b/app/controllers/api/v1/statuses/translations_controller.rb new file mode 100644 index 000000000..540b17d00 --- /dev/null +++ b/app/controllers/api/v1/statuses/translations_controller.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class Api::V1::Statuses::TranslationsController < Api::BaseController + include Authorization + + before_action -> { doorkeeper_authorize! :read, :'read:statuses' } + before_action :set_status + before_action :set_translation + + rescue_from TranslationService::NotConfiguredError, with: :not_found + rescue_from TranslationService::UnexpectedResponseError, TranslationService::QuotaExceededError, TranslationService::TooManyRequestsError, with: :service_unavailable + + 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 |