diff --git a/changedetectionio/api/api_v1.py b/changedetectionio/api/api_v1.py index 07e4022e..e0c7125c 100644 --- a/changedetectionio/api/api_v1.py +++ b/changedetectionio/api/api_v1.py @@ -219,13 +219,15 @@ class CreateWatch(Resource): extras = copy.deepcopy(json_data) - # Because we renamed 'tag' to 'tags' but dont want to change the API (can do this in v2 of the API) + # Because we renamed 'tag' to 'tags' but don't want to change the API (can do this in v2 of the API) + tags = None if extras.get('tag'): - extras['tags'] = extras.get('tag') + tags = extras.get('tag') + del extras['tag'] del extras['url'] - new_uuid = self.datastore.add_watch(url=url, extras=extras) + new_uuid = self.datastore.add_watch(url=url, extras=extras, tag=tags) if new_uuid: self.update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': new_uuid, 'skip_when_checksum_same': True})) return {'uuid': new_uuid}, 201 diff --git a/changedetectionio/store.py b/changedetectionio/store.py index c0f005e6..f0fb3a72 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -249,6 +249,7 @@ class ChangeDetectionStore: # Incase these are copied across, assume it's a reference and deepcopy() apply_extras = deepcopy(extras) + apply_extras['tags'] = [] if not apply_extras.get('tags') else apply_extras.get('tags') # Was it a share link? try to fetch the data if (url.startswith("https://changedetection.io/share/")): @@ -298,14 +299,9 @@ class ChangeDetectionStore: flash('Watch protocol is not permitted by SAFE_PROTOCOL_REGEX', 'error') return None - if extras.get('tags') and type(extras.get('tags')) == str: - extras['tags'] = list(extras.get('tags')) - - if tag: - apply_extras['tags'] = [] - if tag and type(tag) == str: - tag = [tag] - for t in tag: + 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(','): # for each stripped tag, add tag as UUID for a_t in t.split(','): tag_uuid = self.add_tag(a_t) @@ -315,6 +311,10 @@ class ChangeDetectionStore: if tag_uuids: apply_extras['tags'] = list(set(apply_extras['tags'] + tag_uuids)) + # Make any uuids unique + if apply_extras.get('tags'): + apply_extras['tags'] = list(set(apply_extras.get('tags'))) + new_watch = Watch.model(datastore_path=self.datastore_path, url=url) new_uuid = new_watch.get('uuid')