diff --git a/changedetectionio/api/Watch.py b/changedetectionio/api/Watch.py index 293a1c0d3..8874688d2 100644 --- a/changedetectionio/api/Watch.py +++ b/changedetectionio/api/Watch.py @@ -480,6 +480,16 @@ class CreateWatch(Resource): # worker_handler.queue_item_async_safe(self.update_q, queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': new_uuid})) return {'uuid': new_uuid}, 201 else: + # Check if it was a limit issue + page_watch_limit = os.getenv('PAGE_WATCH_LIMIT') + if page_watch_limit: + try: + page_watch_limit = int(page_watch_limit) + current_watch_count = len(self.datastore.data['watching']) + if current_watch_count >= page_watch_limit: + return f"Watch limit reached ({current_watch_count}/{page_watch_limit} watches). Cannot add more watches.", 429 + except ValueError: + pass return "Invalid or unsupported URL", 400 @auth.check_token diff --git a/changedetectionio/store/__init__.py b/changedetectionio/store/__init__.py index 70198a37f..d521df4e0 100644 --- a/changedetectionio/store/__init__.py +++ b/changedetectionio/store/__init__.py @@ -604,6 +604,19 @@ class ChangeDetectionStore(DatastoreUpdatesMixin, FileSavingDataStore): return None + # Check PAGE_WATCH_LIMIT if set + page_watch_limit = os.getenv('PAGE_WATCH_LIMIT') + if page_watch_limit: + try: + page_watch_limit = int(page_watch_limit) + current_watch_count = len(self.__data['watching']) + if current_watch_count >= page_watch_limit: + logger.error(f"Watch limit reached: {current_watch_count}/{page_watch_limit} watches. Cannot add {url}") + flash(gettext("Watch limit reached ({}/{} watches). Cannot add more watches.").format(current_watch_count, page_watch_limit), 'error') + return None + except ValueError: + logger.warning(f"Invalid PAGE_WATCH_LIMIT value: {page_watch_limit}, ignoring limit check") + if tag and type(tag) == str: # Then it's probably a string of the actual tag by name, split and add it for t in tag.split(','):