Disable autocomplete via WHOOGLE_AUTOCOMPLETE var
Setting WHOOGLE_AUTOCOMPLETE to 0 now disables the autocomplete/search suggestion feature. Closes #462main
parent
18688705be
commit
ff885e4fde
33
README.md
33
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-compose`: Uncomment the `env_file` option
|
||||||
- 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. |
|
||||||
| WHOOGLE_PROXY_USER | The username of the proxy server. |
|
| WHOOGLE_PROXY_USER | The username of the proxy server. |
|
||||||
| WHOOGLE_PROXY_PASS | The password 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_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). |
|
| WHOOGLE_PROXY_LOC | The location of the proxy server (host or ip). |
|
||||||
| EXPOSE_PORT | The port where Whoogle will be exposed. |
|
| EXPOSE_PORT | The port where Whoogle will be exposed. |
|
||||||
| HTTPS_ONLY | Enforce HTTPS. (See [here](https://github.com/benbusby/whoogle-search#https-enforcement)) |
|
| 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_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_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_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.
|
||||||
|
|
|
@ -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', '')
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue