[mod] compress saved preferences in url
This commit is contained in:
		
							parent
							
								
									b34124fd8a
								
							
						
					
					
						commit
						5f758b2d39
					
				| @ -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 import settings, autocomplete | ||||||
| from searx.languages import language_codes as languages | 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 | 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['disabled_plugins'] = ','.join(self.plugins.disabled) | ||||||
|         settings_kv['enabled_plugins'] = ','.join(self.plugins.enabled) |         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): |     def parse_dict(self, input_data): | ||||||
|         for user_setting_name, user_setting in input_data.items(): |         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.") }} |         {{ _("These cookies serve your sole convenience, we don't use these cookies to track you.") }} | ||||||
|         </p> |         </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/> |         <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> |         </p> | ||||||
| 
 | 
 | ||||||
|         <input type="submit" class="btn btn-primary" value="{{ _('save') }}" /> |         <input type="submit" class="btn btn-primary" value="{{ _('save') }}" /> | ||||||
|  | |||||||
| @ -2,9 +2,10 @@ from sys import version_info | |||||||
| 
 | 
 | ||||||
| if version_info[0] == 2: | if version_info[0] == 2: | ||||||
|     from urllib import quote, quote_plus, unquote, urlencode |     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: | else: | ||||||
|     from urllib.parse import ( |     from urllib.parse import ( | ||||||
|  |         parse_qs, | ||||||
|         parse_qsl, |         parse_qsl, | ||||||
|         quote, |         quote, | ||||||
|         quote_plus, |         quote_plus, | ||||||
| @ -17,7 +18,8 @@ else: | |||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| __export__ = (parse_qsl, | __export__ = (parse_qs, | ||||||
|  |               parse_qsl, | ||||||
|               quote, |               quote, | ||||||
|               quote_plus, |               quote_plus, | ||||||
|               unquote, |               unquote, | ||||||
|  | |||||||
| @ -403,6 +403,10 @@ def pre_request(): | |||||||
|     for k, v in request.args.items(): |     for k, v in request.args.items(): | ||||||
|         if k not in request.form: |         if k not in request.form: | ||||||
|             request.form[k] = v |             request.form[k] = v | ||||||
|  | 
 | ||||||
|  |     if request.form.get('preferences'): | ||||||
|  |         preferences.parse_encoded_data(request.form['preferences']) | ||||||
|  |     else: | ||||||
|         try: |         try: | ||||||
|             preferences.parse_dict(request.form) |             preferences.parse_dict(request.form) | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Adam Tauber
						Adam Tauber