diff --git a/backend/__init__.py b/backend/__init__.py index 79f49ebf..a92d8590 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -267,29 +267,53 @@ def changedetection_app(conig=None, datastore_o=None): @app.route("/scrub", methods=['GET', 'POST']) @login_required def scrub_page(): - from pathlib import Path global messages + import re if request.method == 'POST': confirmtext = request.form.get('confirmtext') - limit_timestamp = int(request.form.get('limit_date')) + limit_date = request.form.get('limit_date') - if confirmtext == 'scrub': + try: + limit_date = limit_date.replace('T', ' ') + # I noticed chrome will show '/' but actually submit '-' + limit_date = limit_date.replace('-', '/') + # In the case that :ss seconds are supplied + limit_date = re.sub('(\d\d:\d\d)(:\d\d)', '\\1', limit_date) + str_to_dt = datetime.datetime.strptime(limit_date, '%Y/%m/%d %H:%M') + limit_timestamp = int(str_to_dt.timestamp()) + + if limit_timestamp > time.time(): + messages.append({'class': 'error', + 'message': "Timestamp is in the future, cannot continue."}) + return redirect(url_for('scrub_page')) + + except ValueError: + messages.append({'class': 'ok', 'message': 'Incorrect date format, cannot continue.'}) + return redirect(url_for('scrub_page')) + + if confirmtext == 'scrub': + changes_removed = 0 for uuid, watch in datastore.data['watching'].items(): - if len(str(limit_timestamp)) == 10: - datastore.scrub_watch(uuid, limit_timestamp = limit_timestamp) + if limit_timestamp: + changes_removed += datastore.scrub_watch(uuid, limit_timestamp=limit_timestamp) else: - datastore.scrub_watch(uuid) + changes_removed += datastore.scrub_watch(uuid) - messages.append({'class': 'ok', 'message': 'Cleaned all version history.'}) + messages.append({'class': 'ok', + 'message': "Cleared snapshot history ({} snapshots removed)".format( + changes_removed)}) else: - messages.append({'class': 'error', 'message': 'Wrong confirm text.'}) + messages.append({'class': 'error', 'message': 'Incorrect confirmation text.'}) return redirect(url_for('index')) - return render_template("scrub.html") + output = render_template("scrub.html", messages=messages) + messages = [] + return output + # If they edited an existing watch, we need to know to reset the current/previous md5 to include # the excluded text. diff --git a/backend/store.py b/backend/store.py index d4865615..b43a01be 100644 --- a/backend/store.py +++ b/backend/store.py @@ -241,18 +241,20 @@ class ChangeDetectionStore: import hashlib del_timestamps = [] + changes_removed = 0 + for timestamp, path in self.data['watching'][uuid]['history'].items(): if not limit_timestamp or (limit_timestamp is not False and int(timestamp) > limit_timestamp): self.unlink_history_file(path) del_timestamps.append(timestamp) - - + changes_removed += 1 if not limit_timestamp: self.data['watching'][uuid]['last_checked'] = 0 self.data['watching'][uuid]['last_changed'] = 0 self.data['watching'][uuid]['previous_md5'] = 0 + for timestamp in del_timestamps: del self.data['watching'][uuid]['history'][str(timestamp)] @@ -272,9 +274,8 @@ class ChangeDetectionStore: self.data['watching'][uuid]['previous_md5'] = False pass - self.needs_write = True - + return changes_removed def add_watch(self, url, tag): with self.lock: diff --git a/backend/templates/base.html b/backend/templates/base.html index a842af5c..9732c045 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -75,7 +75,6 @@ {% endif %} - {% block content %} {% endblock %} diff --git a/backend/templates/scrub.html b/backend/templates/scrub.html index 3293ebfa..1c57685b 100644 --- a/backend/templates/scrub.html +++ b/backend/templates/scrub.html @@ -2,34 +2,25 @@ {% block content %}
- -
This will remove all version snapshots/data, but keep your list of URLs.
You may like to use the BACKUP link first.
- - Type in the word scrub to confirm that you understand! -
-
- +
-
-
+ + Type in the word scrub to confirm that you understand!
- - +
-
-
- -
- - + + + dd/mm/yyyy hh:mm (24 hour format)
+
@@ -37,12 +28,8 @@ - -
- -
{% endblock %} diff --git a/backend/templates/settings.html b/backend/templates/settings.html index 435909d8..9eade8cc 100644 --- a/backend/templates/settings.html +++ b/backend/templates/settings.html @@ -52,7 +52,7 @@ SMTPS - mailtos://user:pass@mail.domain.com?to=receivingAddress@example.com
Back - Delete history version data + Delete History Snapshot Data