Disable autocomplete via WHOOGLE_AUTOCOMPLETE var

Setting WHOOGLE_AUTOCOMPLETE to 0 now disables the autocomplete/search
suggestion feature.

Closes #462
main
Ben Busby 2021-10-14 18:58:13 -06:00
parent 18688705be
commit ff885e4fde
No known key found for this signature in database
GPG Key ID: 339B7B7EB5333D14
4 changed files with 30 additions and 22 deletions

View File

@ -297,7 +297,7 @@ There are a few optional environment variables available for customizing a Whoog
- With `docker build/run`: Add `--env-file ./whoogle.env` to your command - With `docker build/run`: Add `--env-file ./whoogle.env` to your command
| Variable | Description | | Variable | Description |
| ------------------ | ----------------------------------------------------------------------------------------- | | -------------------- | ----------------------------------------------------------------------------------------- |
| WHOOGLE_DOTENV | Load environment variables in `whoogle.env` | | WHOOGLE_DOTENV | Load environment variables in `whoogle.env` |
| WHOOGLE_USER | The username for basic auth. WHOOGLE_PASS must also be set if used. | | 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_PASS | The password for basic auth. WHOOGLE_USER must also be set if used. |
@ -312,6 +312,7 @@ There are a few optional environment variables available for customizing a Whoog
| WHOOGLE_ALT_IG | The instagram.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_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_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 ### 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. 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.

View File

@ -1,15 +1,10 @@
from app.utils.misc import read_config_bool
from flask import current_app from flask import current_app
import os import os
class Config: class Config:
def __init__(self, **kwargs): 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 app_config = current_app.config
self.url = os.getenv('WHOOGLE_CONFIG_URL', '') self.url = os.getenv('WHOOGLE_CONFIG_URL', '')
self.lang_search = os.getenv('WHOOGLE_CONFIG_SEARCH_LANGUAGE', '') self.lang_search = os.getenv('WHOOGLE_CONFIG_SEARCH_LANGUAGE', '')

View File

@ -16,6 +16,7 @@ from app import app
from app.models.config import Config from app.models.config import Config
from app.request import Request, TorError from app.request import Request, TorError
from app.utils.bangs import resolve_bang 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.session import generate_user_key, valid_user_session
from app.utils.search import * from app.utils.search import *
@ -178,6 +179,10 @@ def search_html():
@app.route('/autocomplete', methods=['GET', 'POST']) @app.route('/autocomplete', methods=['GET', 'POST'])
def autocomplete(): 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') q = g.request_params.get('q')
if not q: if not q:
# FF will occasionally (incorrectly) send the q field without a # FF will occasionally (incorrectly) send the q field without a

View File

@ -8,3 +8,10 @@ def gen_file_hash(path: str, static_file: str) -> str:
filename_split = os.path.splitext(static_file) filename_split = os.path.splitext(static_file)
return filename_split[0] + '.' + file_hash + filename_split[-1] 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