forked from mirrors/LibreTranslate
Add --get-api-key-link
This commit is contained in:
parent
8f8087f8ae
commit
ed68f1bcf9
6 changed files with 25 additions and 3 deletions
|
@ -191,6 +191,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build
|
||||||
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
||||||
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
||||||
| --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Use local API key database` | LT_API_KEYS_REMOTE |
|
| --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Use local API key database` | LT_API_KEYS_REMOTE |
|
||||||
|
| --get-api-key-link | Show a link in the UI where to direct users to get an API key | `Don't show a link` | LT_GET_API_KEY_LINK |
|
||||||
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN |
|
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN |
|
||||||
| --load-only | Set available languages | `all from argostranslate` | LT_LOAD_ONLY |
|
| --load-only | Set available languages | `all from argostranslate` | LT_LOAD_ONLY |
|
||||||
| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS |
|
| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS |
|
||||||
|
|
|
@ -232,6 +232,7 @@ def create_app(args):
|
||||||
gaId=args.ga_id,
|
gaId=args.ga_id,
|
||||||
frontendTimeout=args.frontend_timeout,
|
frontendTimeout=args.frontend_timeout,
|
||||||
api_keys=args.api_keys,
|
api_keys=args.api_keys,
|
||||||
|
get_api_key_link=args.get_api_key_link,
|
||||||
web_version=os.environ.get("LT_WEB") is not None,
|
web_version=os.environ.get("LT_WEB") is not None,
|
||||||
version=get_version()
|
version=get_version()
|
||||||
)
|
)
|
||||||
|
|
|
@ -105,12 +105,17 @@ _default_options_objects = [
|
||||||
'name': 'API_KEYS',
|
'name': 'API_KEYS',
|
||||||
'default_value': False,
|
'default_value': False,
|
||||||
'value_type': 'bool'
|
'value_type': 'bool'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'API_KEYS_REMOTE',
|
'name': 'API_KEYS_REMOTE',
|
||||||
'default_value': '',
|
'default_value': '',
|
||||||
'value_type': 'str'
|
'value_type': 'str'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'name': 'GET_API_KEY_LINK',
|
||||||
|
'default_value': '',
|
||||||
|
'value_type': 'str'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'REQUIRE_API_KEY_ORIGIN',
|
'name': 'REQUIRE_API_KEY_ORIGIN',
|
||||||
'default_value': '',
|
'default_value': '',
|
||||||
|
|
|
@ -95,6 +95,12 @@ def get_args():
|
||||||
type=str,
|
type=str,
|
||||||
help="Use this remote endpoint to query for valid API keys instead of using the local database",
|
help="Use this remote endpoint to query for valid API keys instead of using the local database",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--get-api-key-link",
|
||||||
|
default=DEFARGS['GET_API_KEY_LINK'],
|
||||||
|
type=str,
|
||||||
|
help="Show a link in the UI where to direct users to get an API key",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--require-api-key-origin",
|
"--require-api-key-origin",
|
||||||
type=str,
|
type=str,
|
||||||
|
|
|
@ -436,7 +436,9 @@ function getTextWidth(text) {
|
||||||
function setApiKey(){
|
function setApiKey(){
|
||||||
var prevKey = localStorage.getItem("api_key") || "";
|
var prevKey = localStorage.getItem("api_key") || "";
|
||||||
var newKey = "";
|
var newKey = "";
|
||||||
newKey = window.prompt("Type in your API Key. If you need an API key, contact the server operator.", prevKey);
|
var instructions = "contact the server operator.";
|
||||||
|
if (window.getApiKeyLink) instructions = "press the \"Get API Key\" link."
|
||||||
|
newKey = window.prompt("Type in your API Key. If you need an API key, " + instructions, prevKey);
|
||||||
if (newKey === null) newKey = "";
|
if (newKey === null) newKey = "";
|
||||||
|
|
||||||
localStorage.setItem("api_key", newKey);
|
localStorage.setItem("api_key", newKey);
|
||||||
|
|
|
@ -41,10 +41,14 @@
|
||||||
<button data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></button>
|
<button data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></button>
|
||||||
<a id="logo-container" href="/" class="brand-logo">
|
<a id="logo-container" href="/" class="brand-logo">
|
||||||
<img src="{{ url_for('static', filename='icon.svg') }}" alt="Logo for LibreTranslate" class="logo">
|
<img src="{{ url_for('static', filename='icon.svg') }}" alt="Logo for LibreTranslate" class="logo">
|
||||||
<span>LibreTranslate</span>
|
<span>LibreTranslate</span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="right hide-on-med-and-down">
|
<ul class="right hide-on-med-and-down">
|
||||||
<li><a href="/docs">API Docs</a></li>
|
<li><a href="/docs">API Docs</a></li>
|
||||||
|
{% if get_api_key_link %}
|
||||||
|
<li><a href="{{ get_api_key_link }}">Get API Key</a></li>
|
||||||
|
<script>window.getApiKeyLink = "{{ get_api_key_link }}";</script>
|
||||||
|
{% endif %}
|
||||||
<li><a href="https://github.com/LibreTranslate/LibreTranslate" rel="noopener noreferrer">GitHub</a></li>
|
<li><a href="https://github.com/LibreTranslate/LibreTranslate" rel="noopener noreferrer">GitHub</a></li>
|
||||||
{% if api_keys %}
|
{% if api_keys %}
|
||||||
<li><a href="javascript:setApiKey()" title="Set API Key"><i class="material-icons">vpn_key</i></a></li>
|
<li><a href="javascript:setApiKey()" title="Set API Key"><i class="material-icons">vpn_key</i></a></li>
|
||||||
|
@ -53,6 +57,9 @@
|
||||||
|
|
||||||
<ul id="nav-mobile" class="sidenav">
|
<ul id="nav-mobile" class="sidenav">
|
||||||
<li><a href="/docs">API Docs</a></li>
|
<li><a href="/docs">API Docs</a></li>
|
||||||
|
{% if get_api_key_link %}
|
||||||
|
<li><a href="{{ get_api_key_link }}">Get API Key</a></li>
|
||||||
|
{% endif %}
|
||||||
<li><a href="https://github.com/LibreTranslate/LibreTranslate" rel="noopener noreferrer">GitHub</a></li>
|
<li><a href="https://github.com/LibreTranslate/LibreTranslate" rel="noopener noreferrer">GitHub</a></li>
|
||||||
{% if api_keys %}
|
{% if api_keys %}
|
||||||
<li><a href="javascript:setApiKey()" title="Set API Key"><i class="material-icons">vpn_key</i></a></li>
|
<li><a href="javascript:setApiKey()" title="Set API Key"><i class="material-icons">vpn_key</i></a></li>
|
||||||
|
|
Loading…
Reference in a new issue