From fc20c561bf540d9b187a89a71730b6e3b0bee2da Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Mon, 6 Sep 2021 08:47:11 +0200 Subject: [PATCH] [mod] oa_doi_rewrite plugin: get_doi_resolver: remove args parameter doi_resolvers.get_value('preferences') already contains the value from request.args.get('doi_resolver') --- searx/plugins/oa_doi_rewrite.py | 15 ++++++--------- searx/webapp.py | 4 +--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/searx/plugins/oa_doi_rewrite.py b/searx/plugins/oa_doi_rewrite.py index 02a712942..2dcc01e05 100644 --- a/searx/plugins/oa_doi_rewrite.py +++ b/searx/plugins/oa_doi_rewrite.py @@ -11,8 +11,6 @@ description = gettext('Avoid paywalls by redirecting to open-access versions of default_on = False preference_section = 'general' -doi_resolvers = settings['doi_resolvers'] - def extract_doi(url): match = regex.search(url.path) @@ -25,13 +23,12 @@ def extract_doi(url): return None -def get_doi_resolver(args, preference_doi_resolver): +def get_doi_resolver(preferences): doi_resolvers = settings['doi_resolvers'] - doi_resolver = args.get('doi_resolver', preference_doi_resolver)[0] - if doi_resolver not in doi_resolvers: - doi_resolver = settings['default_doi_resolver'] - doi_resolver_url = doi_resolvers[doi_resolver] - return doi_resolver_url + selected_resolver = preferences.get_value('doi_resolver')[0] + if selected_resolver not in doi_resolvers: + selected_resolver = settings['default_doi_resolver'] + return doi_resolvers[selected_resolver] def on_result(request, search, result): @@ -43,6 +40,6 @@ def on_result(request, search, result): for suffix in ('/', '.pdf', '.xml', '/full', '/meta', '/abstract'): if doi.endswith(suffix): doi = doi[:-len(suffix)] - result['url'] = get_doi_resolver(request.args, request.preferences.get_value('doi_resolver')) + doi + result['url'] = get_doi_resolver(request.preferences) + doi result['parsed_url'] = urlparse(result['url']) return True diff --git a/searx/webapp.py b/searx/webapp.py index 6fcf7c464..cffde08a3 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1040,9 +1040,7 @@ def preferences(): themes = themes, plugins = plugins, doi_resolvers = settings['doi_resolvers'], - current_doi_resolver = get_doi_resolver( - request.args, request.preferences.get_value('doi_resolver') - ), + current_doi_resolver = get_doi_resolver(request.preferences), allowed_plugins = allowed_plugins, theme = get_current_theme_name(), preferences_url_params = request.preferences.get_as_url_params(),