chg: [crawlers] submit a single cookie to the crawler task API

This commit is contained in:
Jean-Louis Huynen 2023-08-31 15:42:44 +02:00
parent 7c73f0944a
commit ed0423118e
No known key found for this signature in database
GPG key ID: 64799157F4BD6B93

View file

@ -1692,6 +1692,18 @@ def api_add_crawler_task(data, user_id=None):
return {'error': 'The access to this cookiejar is restricted'}, 403 return {'error': 'The access to this cookiejar is restricted'}, 403
cookiejar_uuid = cookiejar.uuid cookiejar_uuid = cookiejar.uuid
cookie = data.get('cookie', None)
if not cookiejar_uuid and cookie:
# Create new cookiejar
cookiejar_uuid = create_cookiejar(user_id, "single-shot cookiejar", 1, None)
cookiejar = Cookiejar(cookiejar_uuid)
try:
name = cookie.get('name')
value = cookie.get('value')
cookiejar.add_cookie(name, value, None, None, None, None, None)
except KeyError:
return {'error': 'Invalid cookie key, please submit a valid JSON', 'cookiejar_uuid': cookiejar_uuid}, 400
frequency = data.get('frequency', None) frequency = data.get('frequency', None)
if frequency: if frequency:
if frequency not in ['monthly', 'weekly', 'daily', 'hourly']: if frequency not in ['monthly', 'weekly', 'daily', 'hourly']: