diff --git a/README.md b/README.md index 8877c23..0fe72db 100644 --- a/README.md +++ b/README.md @@ -296,22 +296,23 @@ There are a few optional environment variables available for customizing a Whoog - With `docker-compose`: Uncomment the `env_file` option - With `docker build/run`: Add `--env-file ./whoogle.env` to your command -| Variable | Description | -| ------------------ | ----------------------------------------------------------------------------------------- | -| WHOOGLE_DOTENV | Load environment variables in `whoogle.env` | -| WHOOGLE_USER | The username for basic auth. WHOOGLE_PASS must also be set if used. | -| WHOOGLE_PASS | The password for basic auth. WHOOGLE_USER must also be set if used. | -| WHOOGLE_PROXY_USER | The username of the proxy server. | -| WHOOGLE_PROXY_PASS | The password of the proxy server. | -| WHOOGLE_PROXY_TYPE | The type of the proxy server. Can be "socks5", "socks4", or "http". | -| WHOOGLE_PROXY_LOC | The location of the proxy server (host or ip). | -| EXPOSE_PORT | The port where Whoogle will be exposed. | -| HTTPS_ONLY | Enforce HTTPS. (See [here](https://github.com/benbusby/whoogle-search#https-enforcement)) | -| WHOOGLE_ALT_TW | The twitter.com alternative to use when site alternatives are enabled in the config. | -| WHOOGLE_ALT_YT | The youtube.com alternative to use when site alternatives are enabled in the config. | -| WHOOGLE_ALT_IG | The instagram.com alternative to use when site alternatives are enabled in the config. | -| WHOOGLE_ALT_RD | The reddit.com alternative to use when site alternatives are enabled in the config. | -| WHOOGLE_ALT_TL | The Google Translate alternative to use. This is used for all "translate ____" searches. | +| Variable | Description | +| -------------------- | ----------------------------------------------------------------------------------------- | +| WHOOGLE_DOTENV | Load environment variables in `whoogle.env` | +| WHOOGLE_USER | The username for basic auth. WHOOGLE_PASS must also be set if used. | +| WHOOGLE_PASS | The password for basic auth. WHOOGLE_USER must also be set if used. | +| WHOOGLE_PROXY_USER | The username of the proxy server. | +| WHOOGLE_PROXY_PASS | The password of the proxy server. | +| WHOOGLE_PROXY_TYPE | The type of the proxy server. Can be "socks5", "socks4", or "http". | +| WHOOGLE_PROXY_LOC | The location of the proxy server (host or ip). | +| EXPOSE_PORT | The port where Whoogle will be exposed. | +| HTTPS_ONLY | Enforce HTTPS. (See [here](https://github.com/benbusby/whoogle-search#https-enforcement)) | +| WHOOGLE_ALT_TW | The twitter.com alternative to use when site alternatives are enabled in the config. | +| WHOOGLE_ALT_YT | The youtube.com alternative to use when site alternatives are enabled in the config. | +| WHOOGLE_ALT_IG | The instagram.com alternative to use when site alternatives are enabled in the config. | +| WHOOGLE_ALT_RD | The reddit.com alternative to use when site alternatives are enabled in the config. | +| WHOOGLE_ALT_TL | The Google Translate alternative to use. This is used for all "translate ____" searches. | +| WHOOGLE_AUTOCOMPLETE | Controls visibility of autocomplete/search suggestions. Default on -- use '0' to disable | ### Config Environment Variables These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. diff --git a/app/models/config.py b/app/models/config.py index f865a17..7d0da92 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -1,15 +1,10 @@ +from app.utils.misc import read_config_bool from flask import current_app import os class Config: def __init__(self, **kwargs): - def read_config_bool(var: str) -> bool: - val = os.getenv(var, '0') - if val.isdigit(): - return bool(int(val)) - return False - app_config = current_app.config self.url = os.getenv('WHOOGLE_CONFIG_URL', '') self.lang_search = os.getenv('WHOOGLE_CONFIG_SEARCH_LANGUAGE', '') diff --git a/app/routes.py b/app/routes.py index b5bcca2..35cff9b 100644 --- a/app/routes.py +++ b/app/routes.py @@ -16,6 +16,7 @@ from app import app from app.models.config import Config from app.request import Request, TorError from app.utils.bangs import resolve_bang +from app.utils.misc import read_config_bool from app.utils.session import generate_user_key, valid_user_session from app.utils.search import * @@ -178,6 +179,10 @@ def search_html(): @app.route('/autocomplete', methods=['GET', 'POST']) def autocomplete(): + ac_var = 'WHOOGLE_AUTOCOMPLETE' + if os.getenv(ac_var) and not read_config_bool(ac_var): + return jsonify({}) + q = g.request_params.get('q') if not q: # FF will occasionally (incorrectly) send the q field without a diff --git a/app/utils/misc.py b/app/utils/misc.py index 9327826..01e6935 100644 --- a/app/utils/misc.py +++ b/app/utils/misc.py @@ -8,3 +8,10 @@ def gen_file_hash(path: str, static_file: str) -> str: filename_split = os.path.splitext(static_file) return filename_split[0] + '.' + file_hash + filename_split[-1] + + +def read_config_bool(var: str) -> bool: + val = os.getenv(var, '0') + if val.isdigit(): + return bool(int(val)) + return False