From cdcf4b353f7fb189a405ea5866183e33054bb56f Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 8 Jun 2022 18:32:25 +0200 Subject: [PATCH] New [scrub] button when editing a watch - scrub single watch history (#672) --- changedetectionio/__init__.py | 13 +++++++++++++ changedetectionio/store.py | 19 +++++++++++++++---- changedetectionio/templates/edit.html | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 78966ad0..c285f99a 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -458,6 +458,19 @@ def changedetection_app(config=None, datastore_o=None): return 'OK' + + @app.route("/scrub/", methods=['GET']) + @login_required + def scrub_watch(uuid): + try: + datastore.scrub_watch(uuid) + except KeyError: + flash('Watch not found', 'error') + else: + flash("Scrubbed watch {}".format(uuid)) + + return redirect(url_for('index')) + @app.route("/scrub", methods=['GET', 'POST']) @login_required def scrub_page(): diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 9befd47a..0d33337a 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -254,12 +254,23 @@ class ChangeDetectionStore: def scrub_watch(self, uuid): import pathlib - self.__data['watching'][uuid].update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'previous_md5': False}) - self.needs_write_urgent = True - - for item in pathlib.Path(self.datastore_path).rglob(uuid+"/*.txt"): + self.__data['watching'][uuid].update( + {'last_checked': 0, + 'last_changed': 0, + 'last_viewed': 0, + 'previous_md5': False, + 'last_notification_error': False, + 'last_error': False}) + + # JSON Data, Screenshots, Textfiles (history index and snapshots), HTML in the future etc + for item in pathlib.Path(os.path.join(self.datastore_path, uuid)).rglob("*.*"): unlink(item) + # Force the attr to recalculate + bump = self.__data['watching'][uuid].history + + self.needs_write_urgent = True + def add_watch(self, url, tag="", extras=None, write_to_disk_now=True): if extras is None: diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index e39c082b..009f6ad0 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -259,6 +259,8 @@ nav Delete + Scrub Create Copy