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.
This commit is contained in:
Ben Busby 2021-11-30 21:17:14 -07:00
parent 849282748c
commit 12a6d8d711
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
8 changed files with 132 additions and 31 deletions

View File

@ -37,6 +37,8 @@ class Config:
'theme',
'alts',
'new_tab',
'view_image',
'block',
'safe'
]
@ -107,7 +109,14 @@ class 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:

View File

@ -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
@ -345,7 +354,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'])

View File

@ -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);
}

9
app/static/css/error.css Normal file
View File

@ -0,0 +1,9 @@
html {
font-size: 1.3rem;
}
@media (max-width: 1000px) {
html {
font-size: 3rem;
}
}

View File

@ -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);
}

View File

@ -33,7 +33,9 @@
"translate": "translate",
"light": "light",
"dark": "dark",
"system": "system"
"system": "system",
"ratelimit": "Instance has been ratelimited",
"continue-search": "Continue your search with "
},
"lang_nl": {
"search": "Zoeken",
@ -69,7 +71,9 @@
"translate": "vertalen",
"light": "helder",
"dark": "donker",
"system": "systeeminstellingen"
"system": "systeeminstellingen",
"ratelimit": "Instantie is beperkt in snelheid",
"continue-search": "Ga verder met zoeken met "
},
"lang_de": {
"search": "Suchen",
@ -105,7 +109,9 @@
"translate": "Übersetzen",
"light": "hell",
"dark": "dunkel",
"system": "Systemeinstellung"
"system": "Systemeinstellung",
"ratelimit": "Instanz wurde ratenbegrenzt",
"continue-search": "Setzen Sie Ihre Suche fort mit "
},
"lang_es": {
"search": "Buscar",
@ -141,7 +147,9 @@
"translate": "traducir",
"light": "brillante",
"dark": "oscuro",
"system": "configuración del sistema"
"system": "configuración del sistema",
"ratelimit": "La instancia ha sido ratelimited",
"continue-search": "Continúe su búsqueda con "
},
"lang_it": {
"search": "Cerca",
@ -177,7 +185,9 @@
"translate": "tradurre",
"light": "luminoso",
"dark": "notte",
"system": "impostazioni di sistema"
"system": "impostazioni di sistema",
"ratelimit": "L'istanza è stata limitata alla velocità",
"continue-search": "Continua la tua ricerca con "
},
"lang_pt": {
"search": "Pesquisar",
@ -213,7 +223,9 @@
"translate": "traduzir",
"light": "brilhante",
"dark": "escuro",
"system": "configuração de sistema"
"system": "configuração de sistema",
"ratelimit": "A instância foi limitada pela taxa",
"continue-search": "Continue sua pesquisa com "
},
"lang_ru": {
"search": "Поиск",
@ -249,7 +261,9 @@
"translate": "перевести",
"light": "светлое",
"dark": "темное",
"system": "системное"
"system": "системное",
"ratelimit": "Число экземпляров ограничено",
"continue-search": "Продолжайте поиск с "
},
"lang_zh-CN": {
"search": "搜索",
@ -285,7 +299,9 @@
"translate": "翻译",
"light": "明亮的",
"dark": "黑暗的",
"system": "系统设置"
"system": "系统设置",
"ratelimit": "实例已被限速",
"continue-search": "继续搜索 "
},
"lang_si": {
"search": "සොයන්න",
@ -321,7 +337,9 @@
"translate": "පරිවර්තනය කරන්න",
"light": "දීප්තිමත්",
"dark": "අඳුරු",
"system": "පද්ධතිය"
"system": "පද්ධතිය",
"ratelimit": "උදාහරණය අනුපාත කර ඇත",
"continue-search": "සමඟ ඔබේ සෙවීම දිගටම කරගෙන යන්න"
},
"lang_fr": {
"search": "Chercher",
@ -357,7 +375,9 @@
"translate": "Traduire",
"light": "clair",
"dark": "sombre",
"system": "système"
"system": "système",
"ratelimit": "Le débit de l'instance a été limité",
"continue-search": "Continuez votre recherche avec "
},
"lang_fa": {
"search": "جستجو",
@ -393,7 +413,9 @@
"translate": "ترجمه",
"light": "روشن",
"dark": "تیره",
"system": "سیستم"
"system": "سیستم",
"ratelimit": "نمونه با نرخ محدود شده است",
"continue-search": "جستجوی خود را با "
},
"lang_cs": {
"search": "Hledat",
@ -429,7 +451,9 @@
"translate": "Přeložit",
"light": "Světlý",
"dark": "Tmavý",
"system": "Systémový"
"system": "Systémový",
"ratelimit": "Instance byla omezena sazbou",
"continue-search": "Pokračujte ve vyhledávání pomocí "
},
"lang_zh-TW": {
"search": "搜尋",
@ -465,7 +489,9 @@
"translate": "翻譯",
"light": "明亮的",
"dark": "黑暗的",
"system": "依系統"
"system": "依系統",
"ratelimit": "實例已被限速",
"continue-search": "繼續搜索 "
},
"lang_bg": {
"search": "Търсене",
@ -501,7 +527,9 @@
"translate": "превод",
"light": "светла",
"dark": "тъмна",
"system": "системна"
"system": "системна",
"ratelimit": "Екземплярът е с ограничена скорост",
"continue-search": "Продължете търсенето си с "
},
"lang_hi": {
"search": "खोज",
@ -537,9 +565,11 @@
"translate": "अनुवाद करना",
"light": "रोशनी",
"dark": "अंधेरा",
"system": "प्रणाली"
"system": "प्रणाली",
"ratelimit": "इंस्टेंस को सीमित कर दिया गया है",
"continue-search": "के साथ अपनी खोज जारी रखें "
},
"lang_ja": {
"lang_ja": {
"search": "検索",
"config": "設定",
"config-country": "国を設定する",
@ -573,6 +603,8 @@
"translate": "翻訳",
"light": "ライト",
"dark": "ダーク",
"system": "自動"
}
"system": "自動",
"ratelimit": "インスタンスはレート制限されています",
"continue-search": "で検索を続ける "
}
}

View File

@ -1,6 +1,40 @@
<h1>Error</h1>
<hr>
<p>
Error: "{{ error_message|safe }}"
</p>
<a href="/">Return Home</a>
{% if config.theme %}
{% if config.theme == 'system' %}
<style>
@import "{{ cb_url('light-theme.css') }}" screen;
@import "{{ cb_url('dark-theme.css') }}" screen and (prefers-color-scheme: dark);
</style>
{% else %}
<link rel="stylesheet" href="{{ cb_url(config.theme + '-theme.css') }}"/>
{% endif %}
{% else %}
<link rel="stylesheet" href="{{ cb_url(('dark' if config.dark else 'light') + '-theme.css') }}"/>
{% endif %}
<link rel="stylesheet" href="{{ cb_url('main.css') }}">
<link rel="stylesheet" href="{{ cb_url('error.css') }}">
<style>{{ config.style }}</style>
<div>
<h1>Error</h1>
<p>
{{ error_message|safe }}
</p>
<hr>
<p>
{% if blocked is defined %}
<h4>{{ translation['continue-search'] }} <a class="link" href="https://github.com/benbusby/farside">Farside</a>!</h4>
Whoogle:
<br>
<a class="link-color" href="{{farside}}/whoogle/search?q={{query}}{{params}}">
{{farside}}/whoogle/search?q={{query}}{{params}}
</a>
<br><br>
Searx:
<br>
<a class="link-color" href="{{farside}}/searx/search?q={{query}}">
{{farside}}/searx/search?q={{query}}
</a>
<hr>
{% endif %}
</p>
<a class="link" href="home">Return Home</a>
</div>

View File

@ -1,9 +1,9 @@
<footer>
<p class="footer">
Whoogle Search v{{ version_number }} ||
<a id="gh-link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
<a class="link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
{% if newest_version %}
|| <span class="update_available">Update Available 🟢</span>
{% endif %}
</p>
</footer>
</footer>