From 7a66b69158e60e911a2c1e87f12289f30138397d Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 12 Feb 2022 22:48:29 +0100 Subject: [PATCH] Some work around diff viewing --- changedetectionio/__init__.py | 28 +++++++++++++--- changedetectionio/templates/diff-image.html | 33 +++++++++++++++++++ .../templates/preview-image.html | 13 ++++++++ changedetectionio/templates/preview.html | 2 +- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 changedetectionio/templates/diff-image.html create mode 100644 changedetectionio/templates/preview-image.html diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index bb1dd457..1535fd32 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -695,7 +695,7 @@ def changedetection_app(config=None, datastore_o=None): @app.route("/diff/", methods=['GET']) @login_required def diff_history_page(uuid): - + from changedetectionio import content_fetcher # More for testing, possible to return the first/only if uuid == 'first': uuid = list(datastore.data['watching'].keys()).pop() @@ -734,7 +734,13 @@ def changedetection_app(config=None, datastore_o=None): with open(previous_file, 'r') as f: previous_version_file_contents = f.read() - output = render_template("diff.html", watch_a=watch, + if ('content-type' in watch and content_fetcher.supported_binary_type(watch['content-type'])): + template = "diff-image.html" + else: + template = "diff.html" + + output = render_template(template, + watch_a=watch, newest=newest_version_file_contents, previous=previous_version_file_contents, extra_stylesheets=extra_stylesheets, @@ -751,6 +757,7 @@ def changedetection_app(config=None, datastore_o=None): @app.route("/preview/", methods=['GET']) @login_required def preview_page(uuid): + from changedetectionio import content_fetcher # More for testing, possible to return the first/only if uuid == 'first': @@ -765,14 +772,25 @@ def changedetection_app(config=None, datastore_o=None): return redirect(url_for('index')) newest = list(watch['history'].keys())[-1] - with open(watch['history'][newest], 'r') as f: - content = f.readlines() + fname = watch['history'][newest] + + if ('content-type' in watch and content_fetcher.supported_binary_type(watch['content-type'])): + template = "preview-image.html" + content = fname + else: + template = "preview.html" + try: + with open(fname, 'r') as f: + content = f.read() + except: + content = "Cant read {}".format(fname) output = render_template("preview.html", content=content, extra_stylesheets=extra_stylesheets, current_diff_url=watch['url'], - uuid=uuid) + uuid=uuid, + watch=watch) return output @app.route("/settings/notification-logs", methods=['GET']) diff --git a/changedetectionio/templates/diff-image.html b/changedetectionio/templates/diff-image.html new file mode 100644 index 00000000..3d79ceae --- /dev/null +++ b/changedetectionio/templates/diff-image.html @@ -0,0 +1,33 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Differences

+
+
+ {% if versions|length >= 1 %} + + + + {% endif %} +
+
+ +
+ +
+ +
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/changedetectionio/templates/preview-image.html b/changedetectionio/templates/preview-image.html new file mode 100644 index 00000000..ad063b09 --- /dev/null +++ b/changedetectionio/templates/preview-image.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Current

+
+ +
+ image goes here +
+ +{% endblock %} \ No newline at end of file diff --git a/changedetectionio/templates/preview.html b/changedetectionio/templates/preview.html index 23d80b04..21da0fd0 100644 --- a/changedetectionio/templates/preview.html +++ b/changedetectionio/templates/preview.html @@ -11,7 +11,7 @@ - {% for row in content %}{{row}}{% endfor %} + {{content}}