1646-clone
dgtlmoon 2 years ago
parent 4143b1d676
commit 8369a09930

@ -219,13 +219,15 @@ class CreateWatch(Resource):
extras = copy.deepcopy(json_data) 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'): if extras.get('tag'):
extras['tags'] = extras.get('tag') tags = extras.get('tag')
del extras['tag']
del extras['url'] 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: if new_uuid:
self.update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': new_uuid, 'skip_when_checksum_same': True})) self.update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': new_uuid, 'skip_when_checksum_same': True}))
return {'uuid': new_uuid}, 201 return {'uuid': new_uuid}, 201

@ -249,6 +249,7 @@ class ChangeDetectionStore:
# Incase these are copied across, assume it's a reference and deepcopy() # Incase these are copied across, assume it's a reference and deepcopy()
apply_extras = deepcopy(extras) 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 # Was it a share link? try to fetch the data
if (url.startswith("https://changedetection.io/share/")): if (url.startswith("https://changedetection.io/share/")):
@ -298,14 +299,9 @@ class ChangeDetectionStore:
flash('Watch protocol is not permitted by SAFE_PROTOCOL_REGEX', 'error') flash('Watch protocol is not permitted by SAFE_PROTOCOL_REGEX', 'error')
return None return None
if extras.get('tags') and type(extras.get('tags')) == str: if tag and type(tag) == str:
extras['tags'] = list(extras.get('tags')) # Then it's probably a string of the actual tag by name, split and add it
for t in tag.split(','):
if tag:
apply_extras['tags'] = []
if tag and type(tag) == str:
tag = [tag]
for t in tag:
# for each stripped tag, add tag as UUID # for each stripped tag, add tag as UUID
for a_t in t.split(','): for a_t in t.split(','):
tag_uuid = self.add_tag(a_t) tag_uuid = self.add_tag(a_t)
@ -315,6 +311,10 @@ class ChangeDetectionStore:
if tag_uuids: if tag_uuids:
apply_extras['tags'] = list(set(apply_extras['tags'] + 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_watch = Watch.model(datastore_path=self.datastore_path, url=url)
new_uuid = new_watch.get('uuid') new_uuid = new_watch.get('uuid')

Loading…
Cancel
Save