diff --git a/drama/helpers/aws.py b/drama/helpers/aws.py index 23b7bfd6a..ddb1911eb 100644 --- a/drama/helpers/aws.py +++ b/drama/helpers/aws.py @@ -62,13 +62,14 @@ def upload_file(name, file, resize=None): img = io.BytesIO() i.save(img, format='PNG') req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(img.getvalue())}) + remove(tempname) try: resp = req.json()['data'] except Exception as e: print(e) print(req) print(req.text) - return - remove(tempname) + if "File type invalid" in req.text: return "sex" + else: return else: req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(file.read())}) try: resp = req.json()['data'] @@ -76,7 +77,6 @@ def upload_file(name, file, resize=None): print(e) print(req) print(req.text) - return try: url = resp['link'].replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=9999" except Exception as e: print(e) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 6b810b58c..fd7df94b8 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -34,7 +34,10 @@ def resize(): file.write(chunk) image = upload_from_file("resizing", "resizing", (100, 100)) - if image != None: + if image == "sex": + u.resized = True + g.db.add(u) + elif image != None: u.profileurl = image u.resized = True g.db.add(u)