aboutsummaryrefslogtreecommitdiff
path: root/ignis/views.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-02-11 21:49:51 -0500
committerBobby <[email protected]>2024-02-11 21:49:51 -0500
commit89d1ae0c3579112bd5ea1a868a1d95c7a75314c7 (patch)
tree779edd953f8ce9b633e595846d3b6f5940f6bf4b /ignis/views.py
parenteecd7db0d9caff2131a4d1142a2cf0063acda3a8 (diff)
downloadthatcomputerscientist-89d1ae0c3579112bd5ea1a868a1d95c7a75314c7.tar.xz
thatcomputerscientist-89d1ae0c3579112bd5ea1a868a1d95c7a75314c7.zip
Optimized image serving + bug fixes
Diffstat (limited to 'ignis/views.py')
-rw-r--r--ignis/views.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/ignis/views.py b/ignis/views.py
index d6bd7faf..32c060e7 100644
--- a/ignis/views.py
+++ b/ignis/views.py
@@ -1,6 +1,6 @@
import json
from io import BytesIO
-
+import os
import requests
from captcha.image import ImageCaptcha
from django.core.files.base import ContentFile
@@ -184,11 +184,28 @@ def socialify(request):
url = 'https://socialify.thatcomputerscientist.com/{}/png?description={}&font={}&forks={}&issues={}&language={}&language2={}&name={}&owner=1&pattern={}&pulls={}&stargazers={}&theme={}'.format(repo, description, font, forks, issues, language_1, language_2, name, pattern, pulls, stargazers, theme)
+ image_unique_name = url.replace('https://socialify.thatcomputerscientist.com/', '').replace('/', '_')
+ image_path = 'images/repo_socialify_cache'
+ image_path = '{}/{}.png'.format(image_path, image_unique_name)
+
+ if repo.split('/')[0] == 'luciferreeves':
+ if os.path.exists(image_path):
+ with open(image_path, 'rb') as f:
+ image = f.read()
+ return HttpResponse(image, content_type='image/png')
+
req = requests.get(url)
image = req.content
status = req.status_code
if status == 200:
+ if not os.path.exists('images/repo_socialify_cache'):
+ os.makedirs('images/repo_socialify_cache')
+
+ with open(image_path, 'wb') as f:
+ if repo.split('/')[0] == 'luciferreeves':
+ f.write(image)
+
return HttpResponse(image, content_type='image/png')
else:
with open('static/images/site/utgi.gif', 'rb') as f: