mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 23:41:01 +00:00
Merge pull request #458 from SethFalco/fix-437
fix: don't update url after character-limit
This commit is contained in:
commit
dcc821bc3c
4 changed files with 23 additions and 21 deletions
|
@ -10,11 +10,11 @@ insert_final_newline = true
|
||||||
curly_bracket_next_line = false
|
curly_bracket_next_line = false
|
||||||
spaces_around_operators = true
|
spaces_around_operators = true
|
||||||
|
|
||||||
[*.{js,py}]
|
[*.js]
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
[*.{js,ts}]
|
|
||||||
quote_type = double
|
quote_type = double
|
||||||
|
|
||||||
|
[*.{js,js.template,py}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
[*.{markdown,md}]
|
[*.{markdown,md}]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
|
@ -23,7 +23,7 @@ from flask_babel import Babel
|
||||||
|
|
||||||
from libretranslate import scheduler, flood, secret, remove_translated_files, security, storage
|
from libretranslate import scheduler, flood, secret, remove_translated_files, security, storage
|
||||||
from libretranslate.language import detect_languages, improve_translation_formatting
|
from libretranslate.language import detect_languages, improve_translation_formatting
|
||||||
from libretranslate.locales import (_, _lazy, get_available_locales, get_available_locale_codes, gettext_escaped,
|
from libretranslate.locales import (_, _lazy, get_available_locales, get_available_locale_codes, gettext_escaped,
|
||||||
gettext_html, lazy_swag, get_alternate_locale_links)
|
gettext_html, lazy_swag, get_alternate_locale_links)
|
||||||
|
|
||||||
from .api_keys import Database, RemoteDatabase
|
from .api_keys import Database, RemoteDatabase
|
||||||
|
@ -149,7 +149,7 @@ def create_app(args):
|
||||||
if frontend_argos_language_source is None:
|
if frontend_argos_language_source is None:
|
||||||
frontend_argos_language_source = languages[0]
|
frontend_argos_language_source = languages[0]
|
||||||
|
|
||||||
|
|
||||||
if len(languages) >= 2:
|
if len(languages) >= 2:
|
||||||
language_target_fallback = languages[1]
|
language_target_fallback = languages[1]
|
||||||
else:
|
else:
|
||||||
|
@ -219,7 +219,7 @@ def create_app(args):
|
||||||
if not os.path.isdir(default_mp_dir):
|
if not os.path.isdir(default_mp_dir):
|
||||||
os.mkdir(default_mp_dir)
|
os.mkdir(default_mp_dir)
|
||||||
os.environ["PROMETHEUS_MULTIPROC_DIR"] = default_mp_dir
|
os.environ["PROMETHEUS_MULTIPROC_DIR"] = default_mp_dir
|
||||||
|
|
||||||
from prometheus_client import CONTENT_TYPE_LATEST, Summary, Gauge, CollectorRegistry, multiprocess, generate_latest
|
from prometheus_client import CONTENT_TYPE_LATEST, Summary, Gauge, CollectorRegistry, multiprocess, generate_latest
|
||||||
|
|
||||||
@bp.route("/metrics")
|
@bp.route("/metrics")
|
||||||
|
@ -229,7 +229,7 @@ def create_app(args):
|
||||||
authorization = request.headers.get('Authorization')
|
authorization = request.headers.get('Authorization')
|
||||||
if authorization != "Bearer " + args.metrics_auth_token:
|
if authorization != "Bearer " + args.metrics_auth_token:
|
||||||
abort(401, description=_("Unauthorized"))
|
abort(401, description=_("Unauthorized"))
|
||||||
|
|
||||||
registry = CollectorRegistry()
|
registry = CollectorRegistry()
|
||||||
multiprocess.MultiProcessCollector(registry)
|
multiprocess.MultiProcessCollector(registry)
|
||||||
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)
|
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)
|
||||||
|
@ -258,13 +258,13 @@ def create_app(args):
|
||||||
else:
|
else:
|
||||||
need_key = False
|
need_key = False
|
||||||
key_missing = api_keys_db.lookup(ak) is None
|
key_missing = api_keys_db.lookup(ak) is None
|
||||||
|
|
||||||
if (args.require_api_key_origin
|
if (args.require_api_key_origin
|
||||||
and key_missing
|
and key_missing
|
||||||
and not re.match(args.require_api_key_origin, request.headers.get("Origin", ""))
|
and not re.match(args.require_api_key_origin, request.headers.get("Origin", ""))
|
||||||
):
|
):
|
||||||
need_key = True
|
need_key = True
|
||||||
|
|
||||||
if (args.require_api_key_secret
|
if (args.require_api_key_secret
|
||||||
and key_missing
|
and key_missing
|
||||||
and not secret.secret_match(get_req_secret())
|
and not secret.secret_match(get_req_secret())
|
||||||
|
@ -280,7 +280,7 @@ def create_app(args):
|
||||||
description=description,
|
description=description,
|
||||||
)
|
)
|
||||||
return f(*a, **kw)
|
return f(*a, **kw)
|
||||||
|
|
||||||
if args.metrics:
|
if args.metrics:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def measure_func(*a, **kw):
|
def measure_func(*a, **kw):
|
||||||
|
@ -302,7 +302,7 @@ def create_app(args):
|
||||||
return measure_func
|
return measure_func
|
||||||
else:
|
else:
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@bp.errorhandler(400)
|
@bp.errorhandler(400)
|
||||||
def invalid_api(e):
|
def invalid_api(e):
|
||||||
return jsonify({"error": str(e.description)}), 400
|
return jsonify({"error": str(e.description)}), 400
|
||||||
|
@ -350,17 +350,17 @@ def create_app(args):
|
||||||
if args.disable_web_ui:
|
if args.disable_web_ui:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
response = Response(render_template("app.js.template",
|
response = Response(render_template("app.js.template",
|
||||||
url_prefix=args.url_prefix,
|
url_prefix=args.url_prefix,
|
||||||
get_api_key_link=args.get_api_key_link,
|
get_api_key_link=args.get_api_key_link,
|
||||||
api_secret=secret.get_current_secret() if args.require_api_key_secret else ""), content_type='application/javascript; charset=utf-8')
|
api_secret=secret.get_current_secret() if args.require_api_key_secret else ""), content_type='application/javascript; charset=utf-8')
|
||||||
|
|
||||||
if args.require_api_key_secret:
|
if args.require_api_key_secret:
|
||||||
response.headers['Last-Modified'] = http_date(datetime.now())
|
response.headers['Last-Modified'] = http_date(datetime.now())
|
||||||
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
|
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
|
||||||
response.headers['Pragma'] = 'no-cache'
|
response.headers['Pragma'] = 'no-cache'
|
||||||
response.headers['Expires'] = '-1'
|
response.headers['Expires'] = '-1'
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@bp.get("/languages")
|
@bp.get("/languages")
|
||||||
|
@ -527,6 +527,12 @@ def create_app(args):
|
||||||
if not target_lang:
|
if not target_lang:
|
||||||
abort(400, description=_("Invalid request: missing %(name)s parameter", name='target'))
|
abort(400, description=_("Invalid request: missing %(name)s parameter", name='target'))
|
||||||
|
|
||||||
|
if not request.is_json:
|
||||||
|
# Normalize line endings to UNIX style (LF) only so we can consistently
|
||||||
|
# enforce character limits.
|
||||||
|
# https://www.rfc-editor.org/rfc/rfc2046#section-4.1.1
|
||||||
|
q = "\n".join(q.splitlines())
|
||||||
|
|
||||||
batch = isinstance(q, list)
|
batch = isinstance(q, list)
|
||||||
|
|
||||||
if batch and args.batch_limit != -1:
|
if batch and args.batch_limit != -1:
|
||||||
|
@ -1067,7 +1073,7 @@ def create_app(args):
|
||||||
app.register_blueprint(bp, url_prefix=args.url_prefix)
|
app.register_blueprint(bp, url_prefix=args.url_prefix)
|
||||||
else:
|
else:
|
||||||
app.register_blueprint(bp)
|
app.register_blueprint(bp)
|
||||||
|
|
||||||
limiter.init_app(app)
|
limiter.init_app(app)
|
||||||
|
|
||||||
swag = swagger(app)
|
swag = swagger(app)
|
||||||
|
|
|
@ -108,10 +108,6 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.charactersLimit !== -1 && this.inputText.length >= this.charactersLimit){
|
|
||||||
this.inputText = this.inputText.substring(0, this.charactersLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update "selected" attribute (to overcome a vue.js limitation)
|
// Update "selected" attribute (to overcome a vue.js limitation)
|
||||||
// but properly display checkmarks on supported browsers.
|
// but properly display checkmarks on supported browsers.
|
||||||
// Also change the <select> width value depending on the <option> length
|
// Also change the <select> width value depending on the <option> length
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
<label for="textarea1" class="sr-only">
|
<label for="textarea1" class="sr-only">
|
||||||
{{ _h("Text to translate") }}
|
{{ _h("Text to translate") }}
|
||||||
</label>
|
</label>
|
||||||
<textarea id="textarea1" v-model="inputText" @input="handleInput" ref="inputTextarea" dir="auto"></textarea>
|
<textarea id="textarea1" :maxLength="charactersLimit" v-model="inputText" @input="handleInput" ref="inputTextarea" dir="auto"></textarea>
|
||||||
<button class="btn-delete-text" title="{{ _h('Delete text') }}" aria-label="{{ _h('Delete text') }}" aria-label="Delete text" @click="deleteText">
|
<button class="btn-delete-text" title="{{ _h('Delete text') }}" aria-label="{{ _h('Delete text') }}" aria-label="Delete text" @click="deleteText">
|
||||||
<i class="material-icons">close</i>
|
<i class="material-icons">close</i>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue