Selaa lähdekoodia

[enh] image proxification

Adam Tauber 10 vuotta sitten
vanhempi
commit
01143f48c5
2 muutettua tiedostoa jossa 16 lisäystä ja 0 poistoa
  1. 1
    0
      searx/settings.yml
  2. 15
    0
      searx/webapp.py

+ 1
- 0
searx/settings.yml Näytä tiedosto

@@ -8,6 +8,7 @@ server:
8 8
     default_theme : oscar # ui theme
9 9
     https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py
10 10
     useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
11
+    image_proxy : False # Proxying image results through searx
11 12
 
12 13
 engines:
13 14
   - name : wikipedia

+ 15
- 0
searx/webapp.py Näytä tiedosto

@@ -29,6 +29,7 @@ import os
29 29
 from datetime import datetime, timedelta
30 30
 from requests import get as http_get
31 31
 from itertools import chain
32
+from urllib import urlencode
32 33
 from flask import (
33 34
     Flask, request, render_template, url_for, Response, make_response,
34 35
     redirect, send_from_directory
@@ -204,6 +205,18 @@ def url_for_theme(endpoint, override_theme=None, **values):
204 205
     return url_for(endpoint, **values)
205 206
 
206 207
 
208
+def image_proxify(url):
209
+
210
+    if url.startswith('//'):
211
+        url = 'https:' + url
212
+
213
+    if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
214
+        return url
215
+
216
+    return '{0}?{1}'.format(url_for('image_proxy'),
217
+                            urlencode(dict(url=url)))
218
+
219
+
207 220
 def render(template_name, override_theme=None, **kwargs):
208 221
     blocked_engines = request.cookies.get('blocked_engines', '').split(',')
209 222
 
@@ -250,6 +263,8 @@ def render(template_name, override_theme=None, **kwargs):
250 263
     # override url_for function in templates
251 264
     kwargs['url_for'] = url_for_theme
252 265
 
266
+    kwargs['image_proxify'] = image_proxify
267
+
253 268
     kwargs['get_result_template'] = get_result_template
254 269
 
255 270
     kwargs['theme'] = get_current_theme_name(override=override_theme)