From 4b5d0181b510834949b6dc0b64716162db7d67cc Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 30 Mar 2022 04:11:47 +0000 Subject: [PATCH] Grab links from the sign --- apiserver/apiserver/api/utils_stats.py | 1 + apiserver/apiserver/api/views.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apiserver/apiserver/api/utils_stats.py b/apiserver/apiserver/api/utils_stats.py index 9f17356..cde0a6e 100644 --- a/apiserver/apiserver/api/utils_stats.py +++ b/apiserver/apiserver/api/utils_stats.py @@ -30,6 +30,7 @@ DEFAULTS = { 'track': {}, 'alarm': {}, 'sign': '', + 'link': '', 'autoscan': '', } diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index 7b12f17..1ffbc40 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -576,15 +576,19 @@ class StatsViewSet(viewsets.ViewSet, List): def sign(self, request): try: sign = request.data['sign'][:500] - cache.set('sign', sign) - if secrets.SIGN_TOKEN: - try: - post_data = dict(access_token=secrets.SIGN_TOKEN, args=sign) - r = requests.post('https://api.particle.io/v1/devices/200042000647343232363230/text/', data=post_data, timeout=5) - r.raise_for_status() - except: - raise exceptions.ValidationError(dict(sign='Something went wrong :(')) + if sign.startswith('https://') or sign.startswith('http://'): + cache.set('link', sign) + else: + cache.set('sign', sign) + + if secrets.SIGN_TOKEN: + try: + post_data = dict(access_token=secrets.SIGN_TOKEN, args=sign) + r = requests.post('https://api.particle.io/v1/devices/200042000647343232363230/text/', data=post_data, timeout=5) + r.raise_for_status() + except: + raise exceptions.ValidationError(dict(sign='Something went wrong :(')) return Response(200) except KeyError: