forked from Ponysearch/Ponysearch
[enh] image proxification
This commit is contained in:
parent
60eb831966
commit
01143f48c5
2 changed files with 16 additions and 0 deletions
|
@ -8,6 +8,7 @@ server:
|
||||||
default_theme : oscar # ui theme
|
default_theme : oscar # ui theme
|
||||||
https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py
|
https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py
|
||||||
useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
|
useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
|
||||||
|
image_proxy : False # Proxying image results through searx
|
||||||
|
|
||||||
engines:
|
engines:
|
||||||
- name : wikipedia
|
- name : wikipedia
|
||||||
|
|
|
@ -29,6 +29,7 @@ import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from requests import get as http_get
|
from requests import get as http_get
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from urllib import urlencode
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, request, render_template, url_for, Response, make_response,
|
Flask, request, render_template, url_for, Response, make_response,
|
||||||
redirect, send_from_directory
|
redirect, send_from_directory
|
||||||
|
@ -204,6 +205,18 @@ def url_for_theme(endpoint, override_theme=None, **values):
|
||||||
return url_for(endpoint, **values)
|
return url_for(endpoint, **values)
|
||||||
|
|
||||||
|
|
||||||
|
def image_proxify(url):
|
||||||
|
|
||||||
|
if url.startswith('//'):
|
||||||
|
url = 'https:' + url
|
||||||
|
|
||||||
|
if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
|
||||||
|
return url
|
||||||
|
|
||||||
|
return '{0}?{1}'.format(url_for('image_proxy'),
|
||||||
|
urlencode(dict(url=url)))
|
||||||
|
|
||||||
|
|
||||||
def render(template_name, override_theme=None, **kwargs):
|
def render(template_name, override_theme=None, **kwargs):
|
||||||
blocked_engines = request.cookies.get('blocked_engines', '').split(',')
|
blocked_engines = request.cookies.get('blocked_engines', '').split(',')
|
||||||
|
|
||||||
|
@ -250,6 +263,8 @@ def render(template_name, override_theme=None, **kwargs):
|
||||||
# override url_for function in templates
|
# override url_for function in templates
|
||||||
kwargs['url_for'] = url_for_theme
|
kwargs['url_for'] = url_for_theme
|
||||||
|
|
||||||
|
kwargs['image_proxify'] = image_proxify
|
||||||
|
|
||||||
kwargs['get_result_template'] = get_result_template
|
kwargs['get_result_template'] = get_result_template
|
||||||
|
|
||||||
kwargs['theme'] = get_current_theme_name(override=override_theme)
|
kwargs['theme'] = get_current_theme_name(override=override_theme)
|
||||||
|
|
Loading…
Reference in a new issue