Skip to content

Commit

Permalink
Use farside.link for frontend alternatives in results (#560)
Browse files Browse the repository at this point in the history
* Integrate Farside into Whoogle

When instances are ratelimited (when a captcha is returned instead of
the user's search results) the user can now hop to a new instance via
Farside, a new backend service that redirects users to working instances
of a particular frontend. In this case, it presents a user with a
Farside link to a new Whoogle (or Searx) instance instead, so that the
user can resume their search.

For the generated Farside->Whoogle link, the generated link includes the
user's current Whoogle configuration settings as URL params, to ensure a
more seamless transition between instances. This doesn't translate to
the Farside->Searx link, but potentially could with some changes.

* Expand conversion of config<->url params

Config settings can now be translated to and from URL params using a
predetermined set of "safe" keys (i.e. config settings that easily
translate to URL params).

* Allow jumping instances via Farside when ratelimited

When instances are ratelimited (when a captcha is returned instead of
the user's search results) the user can now hop to a new instance via
Farside, a new backend service that redirects users to working instances
of a particular frontend. In this case, it presents a user with a
Farside link to a new Whoogle (or Searx) instance instead, so that the
user can resume their search.

For the generated Farside->Whoogle link, the generated link includes the
user's current Whoogle configuration settings as URL params, to ensure a
more seamless transition between instances. This doesn't translate to
the Farside->Searx link, but potentially could with some changes.

Closes #554

Closes #559
  • Loading branch information
benbusby committed Dec 9, 2021
1 parent 7bea634 commit 634d179
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 95 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ ENV HTTPS_ONLY=$use_https
ARG whoogle_port=5000
ENV EXPOSE_PORT=$whoogle_port

ARG twitter_alt='nitter.net'
ARG twitter_alt='farside.link/nitter'
ENV WHOOGLE_ALT_TW=$twitter_alt
ARG youtube_alt='invidious.snopyta.org'
ARG youtube_alt='farside.link/invidious'
ENV WHOOGLE_ALT_YT=$youtube_alt
ARG instagram_alt='bibliogram.art/u'
ARG instagram_alt='farside.link/bibliogram'
ENV WHOOGLE_ALT_IG=$instagram_alt
ARG reddit_alt='libredd.it'
ARG reddit_alt='farside.link/libreddit'
ENV WHOOGLE_ALT_RD=$reddit_alt
ARG medium_alt='farside.link/scribe'
ENV WHOOGLE_ALT_MD=$medium_alt
ARG translate_alt='lingva.ml'
ENV WHOOGLE_ALT_TL=$translate_alt
ARG medium_alt='scribe.rip'
ENV WHOOGLE_ALT_MD=$medium_alt

WORKDIR /whoogle

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ Description=Whoogle
# Site alternative configurations, uncomment to enable
# Note: If not set, the feature will still be available
# with default values.
#Environment=WHOOGLE_ALT_TW=nitter.net
#Environment=WHOOGLE_ALT_YT=invidious.snopyta.org
#Environment=WHOOGLE_ALT_IG=bibliogram.art/u
#Environment=WHOOGLE_ALT_RD=libredd.it
#Environment=WHOOGLE_ALT_TW=farside.link/nitter
#Environment=WHOOGLE_ALT_YT=farside.link/invidious
#Environment=WHOOGLE_ALT_IG=farside.link/bibliogram/u
#Environment=WHOOGLE_ALT_RD=farside.link/libreddit
#Environment=WHOOGLE_ALT_MD=farside.link/scribe
#Environment=WHOOGLE_ALT_TL=lingva.ml
#Environment=WHOOGLE_ALT_MD=scribe.rip
# Load values from dotenv only
#Environment=WHOOGLE_DOTENV=1
Type=simple
Expand Down
18 changes: 9 additions & 9 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,34 @@
},
"WHOOGLE_ALT_TW": {
"description": "The site to use as a replacement for twitter.com when site alternatives are enabled in the config.",
"value": "nitter.net",
"value": "farside.link/nitter",
"required": false
},
"WHOOGLE_ALT_YT": {
"description": "The site to use as a replacement for youtube.com when site alternatives are enabled in the config.",
"value": "invidious.snopyta.org",
"value": "farside.link/invidious",
"required": false
},
"WHOOGLE_ALT_IG": {
"description": "The site to use as a replacement for instagram.com when site alternatives are enabled in the config.",
"value": "bibliogram.art/u",
"value": "farside.link/bibliogram/u",
"required": false
},
"WHOOGLE_ALT_RD": {
"description": "The site to use as a replacement for reddit.com when site alternatives are enabled in the config.",
"value": "libredd.it",
"value": "farside.link/libreddit",
"required": false
},
"WHOOGLE_ALT_MD": {
"description": "The site to use as a replacement for medium.com when site alternatives are enabled in the config.",
"value": "farside.link/scribe",
"required": false
},
"WHOOGLE_ALT_TL": {
"description": "The Google Translate alternative to use for all searches following the 'translate ___' structure.",
"value": "lingva.ml",
"required": false
},
"WHOOGLE_ALT_MD": {
"description": "The site to use as a replacement for medium.com when site alternatives are enabled in the config.",
"value": "scribe.rip",
"required": false
},
"WHOOGLE_MINIMAL": {
"description": "Remove everything except basic result cards from all search queries (set to 1 or leave blank)",
"value": "",
Expand Down
35 changes: 30 additions & 5 deletions app/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, **kwargs):
self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '')
self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '')
self.block_url = os.getenv('WHOOGLE_CONFIG_BLOCK_URL', '')
self.ctry = os.getenv('WHOOGLE_CONFIG_COUNTRY', 'US')
self.country = os.getenv('WHOOGLE_CONFIG_COUNTRY', 'US')
self.theme = os.getenv('WHOOGLE_CONFIG_THEME', 'system')
self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE')
self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated
Expand All @@ -33,9 +33,13 @@ def __init__(self, **kwargs):
self.safe_keys = [
'lang_search',
'lang_interface',
'ctry',
'dark',
'theme'
'country',
'theme',
'alts',
'new_tab',
'view_image',
'block',
'safe'
]

# Skip setting custom config if there isn't one
Expand Down Expand Up @@ -105,5 +109,26 @@ def from_params(self, params) -> 'Config':
for param_key in params.keys():
if not self.is_safe_key(param_key):
continue
self[param_key] = params.get(param_key)
param_val = params.get(param_key)

if param_val == 'off':
param_val = False
elif param_val.isdigit():
param_val = int(param_val)

self[param_key] = param_val
return self

def to_params(self) -> str:
"""Generates a set of safe params for using in Whoogle URLs
Returns:
str -- a set of URL parameters
"""
param_str = ''
for safe_key in self.safe_keys:
if not self[safe_key]:
continue
param_str = param_str + f'&{safe_key}={self[safe_key]}'

return param_str
2 changes: 1 addition & 1 deletion app/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def gen_query(query, args, config) -> str:
if 'chips' in args:
param_dict['chips'] = '&chips=' + args.get('chips')

param_dict['gl'] = ('&gl=' + config.ctry) if config.ctry else ''
param_dict['gl'] = ('&gl=' + config.country) if config.country else ''
param_dict['hl'] = '&hl=' + (
config.lang_interface.replace('lang_', '')
if config.lang_interface else ''
Expand Down
13 changes: 11 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,16 @@ def search():
translate_to = localization_lang.replace('lang_', '')

# Return 503 if temporarily blocked by captcha
resp_code = 503 if has_captcha(str(response)) else 200
if has_captcha(str(response)):
return render_template(
'error.html',
blocked=True,
error_message=translation['ratelimit'],
translation=translation,
farside='https://farside.link',
config=g.user_config,
query=urlparse.unquote(query),
params=g.user_config.to_params()), 503
response = bold_search_terms(response, query)

# Feature to display IP address
Expand Down Expand Up @@ -351,7 +360,7 @@ def search():
search_type=search_util.search_type,
mobile=g.user_request.mobile)
if 'isch' not in
search_util.search_type else '')), resp_code
search_util.search_type else '')), 200


@app.route(f'/{Endpoint.config}', methods=['GET', 'POST', 'PUT'])
Expand Down
6 changes: 5 additions & 1 deletion app/static/css/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ select {
color: var(--whoogle-dark-contrast-text) !important;
}

#gh-link {
.link {
color: var(--whoogle-dark-contrast-text);
}

.link-color {
color: var(--whoogle-dark-result-url) !important;
}

.autocomplete-items {
border: 1px solid var(--whoogle-dark-element-bg);
}
Expand Down
9 changes: 9 additions & 0 deletions app/static/css/error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
html {
font-size: 1.3rem;
}

@media (max-width: 1000px) {
html {
font-size: 3rem;
}
}
6 changes: 5 additions & 1 deletion app/static/css/light-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ input {
color: var(--whoogle-contrast-text);
}

#gh-link {
.link {
color: var(--whoogle-element-bg);
}

.link-color {
color: var(--whoogle-result-url) !important;
}

.autocomplete-items {
border: 1px solid var(--whoogle-element-bg);
}
Expand Down
7 changes: 7 additions & 0 deletions app/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,10 @@ details summary {
padding: 10px;
font-weight: bold;
}

/* Mobile styles */
@media (max-width: 1000px) {
select {
width: 100%;
}
}
Loading

0 comments on commit 634d179

Please sign in to comment.