forked from Ponysearch/Ponysearch
[mod] compress saved preferences in url
This commit is contained in:
parent
b34124fd8a
commit
5f758b2d39
4 changed files with 27 additions and 10 deletions
|
@ -1,6 +1,13 @@
|
|||
from base64 import urlsafe_b64encode, urlsafe_b64decode
|
||||
from zlib import compress, decompress
|
||||
from sys import version
|
||||
|
||||
from searx import settings, autocomplete
|
||||
from searx.languages import language_codes as languages
|
||||
from searx.url_utils import urlencode
|
||||
from searx.url_utils import parse_qs, urlencode
|
||||
|
||||
if version[0] == '3':
|
||||
unicode = str
|
||||
|
||||
|
||||
COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years
|
||||
|
@ -279,7 +286,11 @@ class Preferences(object):
|
|||
settings_kv['disabled_plugins'] = ','.join(self.plugins.disabled)
|
||||
settings_kv['enabled_plugins'] = ','.join(self.plugins.enabled)
|
||||
|
||||
return urlencode(settings_kv)
|
||||
return urlsafe_b64encode(compress(urlencode(settings_kv).encode('utf-8'))).decode('utf-8')
|
||||
|
||||
def parse_encoded_data(self, input_data):
|
||||
decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8')))
|
||||
self.parse_dict({x: y[0] for x,y in parse_qs(unicode(decoded_data)).items()})
|
||||
|
||||
def parse_dict(self, input_data):
|
||||
for user_setting_name, user_setting in input_data.items():
|
||||
|
|
|
@ -287,7 +287,7 @@
|
|||
{{ _("These cookies serve your sole convenience, we don't use these cookies to track you.") }}
|
||||
</p>
|
||||
<p style="margin:20px 0;">{{ _('Search URL of the currently saved preferences') }} <small class="text-muted">({{ _('Note: specifying custom settings in the search URL can reduce privacy by leaking data to the clicked result sites.') }})</small>:<br/>
|
||||
<input readonly="" class="form-control select-all-on-click cursor-text" type="url" value="{{ url_for('index', _external=True) }}?{{ preferences_url_params|e }}{% raw %}&q=%s{% endraw %}">
|
||||
<input readonly="" class="form-control select-all-on-click cursor-text" type="url" value="{{ url_for('index', _external=True) }}?preferences={{ preferences_url_params|e }}{% raw %}&q=%s{% endraw %}">
|
||||
</p>
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="{{ _('save') }}" />
|
||||
|
|
|
@ -2,9 +2,10 @@ from sys import version_info
|
|||
|
||||
if version_info[0] == 2:
|
||||
from urllib import quote, quote_plus, unquote, urlencode
|
||||
from urlparse import parse_qsl, urljoin, urlparse, urlunparse, ParseResult
|
||||
from urlparse import parse_qs, parse_qsl, urljoin, urlparse, urlunparse, ParseResult
|
||||
else:
|
||||
from urllib.parse import (
|
||||
parse_qs,
|
||||
parse_qsl,
|
||||
quote,
|
||||
quote_plus,
|
||||
|
@ -17,7 +18,8 @@ else:
|
|||
)
|
||||
|
||||
|
||||
__export__ = (parse_qsl,
|
||||
__export__ = (parse_qs,
|
||||
parse_qsl,
|
||||
quote,
|
||||
quote_plus,
|
||||
unquote,
|
||||
|
|
|
@ -403,11 +403,15 @@ def pre_request():
|
|||
for k, v in request.args.items():
|
||||
if k not in request.form:
|
||||
request.form[k] = v
|
||||
try:
|
||||
preferences.parse_dict(request.form)
|
||||
except Exception as e:
|
||||
logger.exception('invalid settings')
|
||||
request.errors.append(gettext('Invalid settings'))
|
||||
|
||||
if request.form.get('preferences'):
|
||||
preferences.parse_encoded_data(request.form['preferences'])
|
||||
else:
|
||||
try:
|
||||
preferences.parse_dict(request.form)
|
||||
except Exception as e:
|
||||
logger.exception('invalid settings')
|
||||
request.errors.append(gettext('Invalid settings'))
|
||||
|
||||
# request.user_plugins
|
||||
request.user_plugins = []
|
||||
|
|
Loading…
Reference in a new issue