From c7169ebba18a76cde9f9b75568dae340eb38c1f0 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 10 Apr 2021 14:31:57 +0930 Subject: [PATCH] Validate duplicate URLs --- backend/__init__.py | 7 ++++++- backend/store.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index ce2c20eb..602c446d 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -483,8 +483,13 @@ def changedetection_app(config=None, datastore_o=None): def api_watch_add(): global messages + url = request.form.get('url').strip() + if datastore.url_exists(url): + messages.append({'class': 'error', 'message': 'The URL {} already exists'.format(url)}) + return redirect(url_for('index')) + # @todo add_watch should throw a custom Exception for validation etc - new_uuid = datastore.add_watch(url=request.form.get('url').strip(), tag=request.form.get('tag').strip()) + new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip()) # Straight into the queue. update_q.put(new_uuid) diff --git a/backend/store.py b/backend/store.py index be5875fc..e51a0f61 100644 --- a/backend/store.py +++ b/backend/store.py @@ -211,7 +211,7 @@ class ChangeDetectionStore: def url_exists(self, url): # Probably their should be dict... - for watch in self.data['watching']: + for watch in self.data['watching'].values(): if watch['url'] == url: return True