Browse Source

Fix inability to use local LibreTranslate without setting ALLOWED_PRIVATE_ADDRESSES (#21926)

Fixes #20029
closed-social-glitch-2
Claire 1 year ago
committed by GitHub
parent
commit
673c54f114
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions
  1. +2
    -1
      app/lib/request.rb
  2. +1
    -1
      app/lib/translation_service/libre_translate.rb

+ 2
- 1
app/lib/request.rb View File

@ -30,7 +30,8 @@ class Request
@verb = verb
@url = Addressable::URI.parse(url).normalize
@http_client = options.delete(:http_client)
@options = options.merge(socket_class: use_proxy? ? ProxySocket : Socket)
@allow_local = options.delete(:allow_local)
@options = options.merge(socket_class: use_proxy? || @allow_local ? ProxySocket : Socket)
@options = @options.merge(proxy_url) if use_proxy?
@headers = {}

+ 1
- 1
app/lib/translation_service/libre_translate.rb View File

@ -27,7 +27,7 @@ class TranslationService::LibreTranslate < TranslationService
def request(text, source_language, target_language)
body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key)
req = Request.new(:post, "#{@base_url}/translate", body: body)
req = Request.new(:post, "#{@base_url}/translate", body: body, allow_local: true)
req.add_headers('Content-Type': 'application/json')
req
end

Loading…
Cancel
Save