diff --git a/README.md b/README.md index bdb4eb3..0f32081 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build | --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-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 | | --load-only | Set available languages | `all from argostranslate` | LT_LOAD_ONLY | | --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS | diff --git a/app/app.py b/app/app.py index cba22a2..17c595a 100644 --- a/app/app.py +++ b/app/app.py @@ -232,6 +232,7 @@ def create_app(args): gaId=args.ga_id, frontendTimeout=args.frontend_timeout, api_keys=args.api_keys, + get_api_key_link=args.get_api_key_link, web_version=os.environ.get("LT_WEB") is not None, version=get_version() ) diff --git a/app/default_values.py b/app/default_values.py index f8043b5..70d3911 100644 --- a/app/default_values.py +++ b/app/default_values.py @@ -105,12 +105,17 @@ _default_options_objects = [ 'name': 'API_KEYS', 'default_value': False, 'value_type': 'bool' - }, + }, { 'name': 'API_KEYS_REMOTE', 'default_value': '', 'value_type': 'str' }, + { + 'name': 'GET_API_KEY_LINK', + 'default_value': '', + 'value_type': 'str' + }, { 'name': 'REQUIRE_API_KEY_ORIGIN', 'default_value': '', diff --git a/app/main.py b/app/main.py index 9e44050..e179661 100644 --- a/app/main.py +++ b/app/main.py @@ -95,6 +95,12 @@ def get_args(): type=str, 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( "--require-api-key-origin", type=str, diff --git a/app/static/js/app.js b/app/static/js/app.js index f81cdb2..de29041 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -436,7 +436,9 @@ function getTextWidth(text) { function setApiKey(){ var prevKey = localStorage.getItem("api_key") || ""; 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 = ""; localStorage.setItem("api_key", newKey); diff --git a/app/templates/index.html b/app/templates/index.html index 8862ec5..b7d6cc7 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -41,10 +41,14 @@