From 1aae6220e5eb293e43fcaf4adadf28b707600eaa Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 19 Aug 2025 16:14:51 +0200 Subject: [PATCH] API - Recheck by tag #3356 --- changedetectionio/api/Tags.py | 24 ++++++++++++++++++++++-- changedetectionio/flask_app.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/changedetectionio/api/Tags.py b/changedetectionio/api/Tags.py index b001edc2..13332df2 100644 --- a/changedetectionio/api/Tags.py +++ b/changedetectionio/api/Tags.py @@ -1,5 +1,8 @@ +from changedetectionio import queuedWatchMetaData +from changedetectionio import worker_handler from flask_expects_json import expects_json from flask_restful import abort, Resource + from flask import request from . import auth @@ -11,21 +14,24 @@ class Tag(Resource): def __init__(self, **kwargs): # datastore is a black box dependency self.datastore = kwargs['datastore'] + self.update_q = kwargs['update_q'] # Get information about a single tag # curl http://localhost:5000/api/v1/tag/ @auth.check_token def get(self, uuid): """ - @api {get} /api/v1/tag/:uuid Single tag - get data or toggle notification muting. - @apiDescription Retrieve tag information and set notification_muted status + @api {get} /api/v1/tag/:uuid Single tag - Get data, toggle notification muting, recheck all. + @apiDescription Retrieve tag information, set notification_muted status, recheck all in tag. @apiExample {curl} Example usage: curl http://localhost:5000/api/v1/tag/cc0cfffa-f449-477b-83ea-0caafd1dc091 -H"x-api-key:813031b16330fe25e3780cf0325daa45" curl "http://localhost:5000/api/v1/tag/cc0cfffa-f449-477b-83ea-0caafd1dc091?muted=muted" -H"x-api-key:813031b16330fe25e3780cf0325daa45" + curl "http://localhost:5000/api/v1/tag/cc0cfffa-f449-477b-83ea-0caafd1dc091?recheck=true" -H"x-api-key:813031b16330fe25e3780cf0325daa45" @apiName Tag @apiGroup Tag @apiParam {uuid} uuid Tag unique ID. @apiQuery {String} [muted] =`muted` or =`unmuted` , Sets the MUTE NOTIFICATIONS state + @apiQuery {String} [recheck] = True, Queue all watches with this tag for recheck @apiSuccess (200) {String} OK When muted operation OR full JSON object of the tag @apiSuccess (200) {JSON} TagJSON JSON Full JSON object of the tag """ @@ -34,6 +40,20 @@ class Tag(Resource): if not tag: abort(404, message=f'No tag exists with the UUID of {uuid}') + if request.args.get('recheck'): + # Recheck all, including muted + # Get most overdue first + i=0 + for k in sorted(self.datastore.data['watching'].items(), key=lambda item: item[1].get('last_checked', 0)): + watch_uuid = k[0] + watch = k[1] + if not watch['paused'] and tag not in watch['tags']: + continue + worker_handler.queue_item_async_safe(self.update_q, queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': watch_uuid})) + i+=1 + + return f"OK, {i} watches queued", 200 + if request.args.get('muted', '') == 'muted': self.datastore.data['settings']['application']['tags'][uuid]['notification_muted'] = True return "OK", 200 diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index b4d4f076..231346d9 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -326,7 +326,7 @@ def changedetection_app(config=None, datastore_o=None): resource_class_kwargs={'datastore': datastore}) watch_api.add_resource(Tags, '/api/v1/tags', - resource_class_kwargs={'datastore': datastore}) + resource_class_kwargs={'datastore': datastore, 'update_q': update_q}) watch_api.add_resource(Tag, '/api/v1/tag', '/api/v1/tag/', resource_class_kwargs={'datastore': datastore})