From 992dc84e00dce31b341b284c4039d8f7b1e124b9 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Mon, 20 May 2024 10:41:15 +0200 Subject: [PATCH] fix: [modules] Gracefully accept no hashlookup fixes #916 --- cache/run_redis.sh | 4 +++- indexing/run_redis.sh | 5 ++++- website/web/__init__.py | 12 ++++++++---- website/web/templates/hashlookup.html | 5 +++++ website/web/templates/tree.html | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cache/run_redis.sh b/cache/run_redis.sh index c7e47b52..50a49c74 100755 --- a/cache/run_redis.sh +++ b/cache/run_redis.sh @@ -5,6 +5,8 @@ set -x if [ -f ../../valkey/src/valkey-server ]; then ../../valkey/src/valkey-server ./cache.conf -else +elif [ -f ../../redis/src/redis-server ]; then ../../redis/src/redis-server ./cache.conf +else + /usr/bin/redis-server ./cache.conf fi diff --git a/indexing/run_redis.sh b/indexing/run_redis.sh index 056d33cb..46c4a00a 100755 --- a/indexing/run_redis.sh +++ b/indexing/run_redis.sh @@ -5,6 +5,9 @@ set -x if [ -f ../../valkey/src/valkey-server ]; then ../../valkey/src/valkey-server ./indexing.conf -else +elif [ -f ../../redis/src/redis-server ]; then ../../redis/src/redis-server ./indexing.conf +else + /usr/bin/redis-server ./indexing.conf + fi diff --git a/website/web/__init__.py b/website/web/__init__.py index 90c5bfa8..ee26554b 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -962,10 +962,14 @@ def urls_rendered_page(tree_uuid: str) -> WerkzeugResponse | str | Response: @app.route('/tree//hashlookup', methods=['GET']) def hashlookup(tree_uuid: str) -> str | WerkzeugResponse | Response: - merged, total_ressources = lookyloo.merge_hashlookup_tree(tree_uuid) - # We only want unique URLs for the template - for sha1, entries in merged.items(): - entries['nodes'] = {node.name for node in entries['nodes']} + try: + merged, total_ressources = lookyloo.merge_hashlookup_tree(tree_uuid) + # We only want unique URLs for the template + for sha1, entries in merged.items(): + entries['nodes'] = {node.name for node in entries['nodes']} + except Exception: # error or module not enabled + merged = False + total_ressources = False return render_template('hashlookup.html', base_tree_uuid=tree_uuid, merged=merged, total_ressources=total_ressources) diff --git a/website/web/templates/hashlookup.html b/website/web/templates/hashlookup.html index 95e56f02..3d31f4a6 100644 --- a/website/web/templates/hashlookup.html +++ b/website/web/templates/hashlookup.html @@ -1,4 +1,8 @@
+{% if not merged %} + No result data available or hashlookup module not enabled. +{%else%} + Total Hits: {{ merged|length }}
Total ressources: {{total_ressources}}

{% for sha1, entries in merged.items() %} @@ -25,4 +29,5 @@ {% endfor %} +{%endif%}
diff --git a/website/web/templates/tree.html b/website/web/templates/tree.html index c2928973..c48d2792 100644 --- a/website/web/templates/tree.html +++ b/website/web/templates/tree.html @@ -434,7 +434,7 @@ {% endif %} - ? + ?