Add more OpenSearch definitions (for images etc.)

This commit is contained in:
Anna “CyberTailor” 2022-06-14 15:43:57 +05:00
parent 2600ad5a05
commit 5eb275b500
No known key found for this signature in database
GPG Key ID: E7B76EDC50864BB1
3 changed files with 24 additions and 5 deletions

View File

@ -3,7 +3,6 @@ import base64
import io import io
import os import os
import json import json
import os
import pickle import pickle
import urllib.parse as urlparse import urllib.parse as urlparse
import uuid import uuid
@ -26,7 +25,7 @@ from app.utils.session import generate_user_key, valid_user_session
from bs4 import BeautifulSoup as bsoup from bs4 import BeautifulSoup as bsoup
from flask import jsonify, make_response, request, redirect, render_template, \ from flask import jsonify, make_response, request, redirect, render_template, \
send_file, session, url_for, g send_file, session, url_for, g
from requests import exceptions, get from requests import exceptions
from requests.models import PreparedRequest from requests.models import PreparedRequest
from cryptography.fernet import Fernet, InvalidToken from cryptography.fernet import Fernet, InvalidToken
from cryptography.exceptions import InvalidSignature from cryptography.exceptions import InvalidSignature
@ -38,6 +37,12 @@ ac_var = 'WHOOGLE_AUTOCOMPLETE'
autocomplete_enabled = os.getenv(ac_var, '1') autocomplete_enabled = os.getenv(ac_var, '1')
def get_search_name(tbm):
for tab in app.config['HEADER_TABS'].values():
if tab['tbm'] == tbm:
return tab['name']
def auth_required(f): def auth_required(f):
@wraps(f) @wraps(f)
def decorated(*args, **kwargs): def decorated(*args, **kwargs):
@ -252,7 +257,9 @@ def opensearch():
return render_template( return render_template(
'opensearch.xml', 'opensearch.xml',
main_url=opensearch_url, main_url=opensearch_url,
request_type='' if get_only else 'method="post"' request_type='' if get_only else 'method="post"',
search_type=request.args.get('tbm'),
search_name=get_search_name(request.args.get('tbm'))
), 200, {'Content-Type': 'application/xml'} ), 200, {'Content-Type': 'application/xml'}
@ -368,6 +375,7 @@ def search():
has_update=app.config['HAS_UPDATE'], has_update=app.config['HAS_UPDATE'],
query=urlparse.unquote(query), query=urlparse.unquote(query),
search_type=search_util.search_type, search_type=search_util.search_type,
search_name=get_search_name(search_util.search_type),
config=g.user_config, config=g.user_config,
autocomplete_enabled=autocomplete_enabled, autocomplete_enabled=autocomplete_enabled,
lingva_url=app.config['TRANSLATE_URL'], lingva_url=app.config['TRANSLATE_URL'],

View File

@ -2,7 +2,11 @@
<head> <head>
<link rel="shortcut icon" href="static/img/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="static/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="static/img/favicon.ico" type="image/x-icon"> <link rel="icon" href="static/img/favicon.ico" type="image/x-icon">
<link rel="search" href="opensearch.xml" type="application/opensearchdescription+xml" title="Whoogle Search"> {% if not search_type %}
<link rel="search" href="opensearch.xml" type="application/opensearchdescription+xml" title="Whoogle Search">
{% else %}
<link rel="search" href="opensearch.xml?tbm={{ search_type }}" type="application/opensearchdescription+xml" title="Whoogle Search ({{ search_name }})">
{% endif %}
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer"> <meta name="referrer" content="no-referrer">
<link rel="stylesheet" href="{{ cb_url('logo.css') }}"> <link rel="stylesheet" href="{{ cb_url('logo.css') }}">

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/"> xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Whoogle</ShortName> {% if not search_type %}
<ShortName>Whoogle</ShortName>
{% else %}
<ShortName>Whoogle {{ search_name }}</ShortName>
{% endif %}
<Description>Whoogle: A lightweight, deployable Google search proxy for desktop/mobile that removes Javascript, AMP links, and ads <Description>Whoogle: A lightweight, deployable Google search proxy for desktop/mobile that removes Javascript, AMP links, and ads
</Description> </Description>
<InputEncoding>UTF-8</InputEncoding> <InputEncoding>UTF-8</InputEncoding>
@ -10,6 +14,9 @@
</Image> </Image>
<Url type="text/html" {{ request_type|safe }} template="{{ main_url }}/search"> <Url type="text/html" {{ request_type|safe }} template="{{ main_url }}/search">
<Param name="q" value="{searchTerms}"/> <Param name="q" value="{searchTerms}"/>
{% if search_type %}
<Param name="tbm" value="{{ search_type }}"/>
{% endif %}
</Url> </Url>
<Url type="application/x-suggestions+json" {{ request_type|safe }} template="{{ main_url }}/autocomplete"> <Url type="application/x-suggestions+json" {{ request_type|safe }} template="{{ main_url }}/autocomplete">
<Param name="q" value="{searchTerms}"/> <Param name="q" value="{searchTerms}"/>