Cache images (max-age=300)

This commit is contained in:
Oliver Falk
2019-03-08 12:29:50 +01:00
parent 3a914c218a
commit bb5358a267

View File

@@ -147,9 +147,11 @@ class AvatarImageView(TemplateView):
data = BytesIO()
monsterdata.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
return HttpResponse(
response = HttpResponse(
data,
content_type='image/png')
response['Cache-Control'] = 'max-age=300'
return response
if str(default) == 'robohash':
roboset = 'any'
@@ -160,9 +162,11 @@ class AvatarImageView(TemplateView):
data = BytesIO()
robohash.img.save(data, format='png')
data.seek(0)
return HttpResponse(
response = HttpResponse(
data,
content_type='image/png')
response['Cache-Control'] = 'max-age=300'
return response
if str(default) == 'retro':
identicon = Identicon.render(kwargs['digest'])
@@ -171,9 +175,11 @@ class AvatarImageView(TemplateView):
img = img.resize((size, size), Image.ANTIALIAS)
img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
return HttpResponse(
response = HttpResponse(
data,
content_type='image/png')
response['Cache-Control'] = 'max-age=300'
return response
if str(default) == 'pagan':
paganobj = pagan.Avatar(kwargs['digest'])
@@ -181,9 +187,11 @@ class AvatarImageView(TemplateView):
img = paganobj.img.resize((size, size), Image.ANTIALIAS)
img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
return HttpResponse(
response = HttpResponse(
data,
content_type='image/png')
response['Cache-Control'] = 'max-age=300'
return response
if str(default) == 'identicon':
p = Pydenticon5()
@@ -193,9 +201,11 @@ class AvatarImageView(TemplateView):
data = BytesIO()
img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
return HttpResponse(
response = HttpResponse(
data,
content_type='image/png')
response['Cache-Control'] = 'max-age=300'
return response
if str(default) == 'mm' or str(default) == 'mp':
# If mm is explicitly given, we need to catch that
@@ -231,9 +241,11 @@ class AvatarImageView(TemplateView):
obj.save()
if imgformat == 'jpg':
imgformat = 'jpeg'
return HttpResponse(
response = HttpResponse(
data,
content_type='image/%s' % imgformat)
response['Cache-Control'] = 'max-age=300'
return response
class GravatarProxyView(View):
'''
@@ -302,9 +314,11 @@ class GravatarProxyView(View):
data = BytesIO(gravatarimagedata.read())
img = Image.open(data)
data.seek(0)
return HttpResponse(
response = HttpResponse(
data.read(),
content_type='image/%s' % file_format(img.format))
response['Cache-Control'] = 'max-age=300'
return response
except ValueError as exc:
print('Value error: %s' % exc)