Improved handling of default country
Also added fallback 1px empty gif as a replacement for images that fail to load
This commit is contained in:
parent
387e19bba6
commit
4bf013ccd0
|
@ -51,6 +51,7 @@ class Config:
|
||||||
]
|
]
|
||||||
|
|
||||||
COUNTRIES = [
|
COUNTRIES = [
|
||||||
|
{'name': 'Default (use server location)', 'value': ''},
|
||||||
{'name': 'Afghanistan', 'value': 'countryAF'},
|
{'name': 'Afghanistan', 'value': 'countryAF'},
|
||||||
{'name': 'Albania', 'value': 'countryAL'},
|
{'name': 'Albania', 'value': 'countryAL'},
|
||||||
{'name': 'Algeria', 'value': 'countryDZ'},
|
{'name': 'Algeria', 'value': 'countryDZ'},
|
||||||
|
|
|
@ -46,7 +46,7 @@ def gen_query(query, args, config, near_city=None):
|
||||||
param_dict['start'] = '&start=' + args.get('start')
|
param_dict['start'] = '&start=' + args.get('start')
|
||||||
|
|
||||||
# Search for results near a particular city, if available
|
# Search for results near a particular city, if available
|
||||||
if near_city is not None:
|
if near_city:
|
||||||
param_dict['near'] = '&near=' + urlparse.quote(near_city)
|
param_dict['near'] = '&near=' + urlparse.quote(near_city)
|
||||||
|
|
||||||
# Set language for results (lr) and interface (hl)
|
# Set language for results (lr) and interface (hl)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from app.filter import Filter, get_first_link
|
||||||
from app.models.config import Config
|
from app.models.config import Config
|
||||||
from app.request import Request, gen_query
|
from app.request import Request, gen_query
|
||||||
import argparse
|
import argparse
|
||||||
|
import base64
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from cryptography.fernet import Fernet, InvalidToken
|
from cryptography.fernet import Fernet, InvalidToken
|
||||||
from flask import g, make_response, request, redirect, render_template, send_file
|
from flask import g, make_response, request, redirect, render_template, send_file
|
||||||
|
@ -10,6 +11,7 @@ from functools import wraps
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from pycurl import error as pycurl_error
|
||||||
import urllib.parse as urlparse
|
import urllib.parse as urlparse
|
||||||
import waitress
|
import waitress
|
||||||
|
|
||||||
|
@ -163,17 +165,24 @@ def imgres():
|
||||||
def tmp():
|
def tmp():
|
||||||
cipher_suite = Fernet(app.secret_key)
|
cipher_suite = Fernet(app.secret_key)
|
||||||
img_url = cipher_suite.decrypt(request.args.get('image_url').encode()).decode()
|
img_url = cipher_suite.decrypt(request.args.get('image_url').encode()).decode()
|
||||||
file_data = g.user_request.send(base_url=img_url, return_bytes=True)
|
|
||||||
tmp_mem = io.BytesIO()
|
|
||||||
tmp_mem.write(file_data)
|
|
||||||
tmp_mem.seek(0)
|
|
||||||
|
|
||||||
return send_file(
|
try:
|
||||||
tmp_mem,
|
file_data = g.user_request.send(base_url=img_url, return_bytes=True)
|
||||||
as_attachment=True,
|
tmp_mem = io.BytesIO()
|
||||||
attachment_filename='tmp.png',
|
tmp_mem.write(file_data)
|
||||||
mimetype='image/png'
|
tmp_mem.seek(0)
|
||||||
)
|
|
||||||
|
return send_file(
|
||||||
|
tmp_mem,
|
||||||
|
as_attachment=True,
|
||||||
|
attachment_filename='tmp.png',
|
||||||
|
mimetype='image/png'
|
||||||
|
)
|
||||||
|
except pycurl_error:
|
||||||
|
pass
|
||||||
|
|
||||||
|
empty_gif = base64.b64decode('R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
|
||||||
|
return send_file(io.BytesIO(empty_gif), mimetype='image/gif')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/window')
|
@app.route('/window')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user