mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-16 21:18:02 +00:00
Cache images (max-age=300)
This commit is contained in:
@@ -147,9 +147,11 @@ class AvatarImageView(TemplateView):
|
|||||||
data = BytesIO()
|
data = BytesIO()
|
||||||
monsterdata.save(data, 'PNG', quality=JPEG_QUALITY)
|
monsterdata.save(data, 'PNG', quality=JPEG_QUALITY)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
if str(default) == 'robohash':
|
if str(default) == 'robohash':
|
||||||
roboset = 'any'
|
roboset = 'any'
|
||||||
@@ -160,9 +162,11 @@ class AvatarImageView(TemplateView):
|
|||||||
data = BytesIO()
|
data = BytesIO()
|
||||||
robohash.img.save(data, format='png')
|
robohash.img.save(data, format='png')
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
if str(default) == 'retro':
|
if str(default) == 'retro':
|
||||||
identicon = Identicon.render(kwargs['digest'])
|
identicon = Identicon.render(kwargs['digest'])
|
||||||
@@ -171,9 +175,11 @@ class AvatarImageView(TemplateView):
|
|||||||
img = img.resize((size, size), Image.ANTIALIAS)
|
img = img.resize((size, size), Image.ANTIALIAS)
|
||||||
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
if str(default) == 'pagan':
|
if str(default) == 'pagan':
|
||||||
paganobj = pagan.Avatar(kwargs['digest'])
|
paganobj = pagan.Avatar(kwargs['digest'])
|
||||||
@@ -181,9 +187,11 @@ class AvatarImageView(TemplateView):
|
|||||||
img = paganobj.img.resize((size, size), Image.ANTIALIAS)
|
img = paganobj.img.resize((size, size), Image.ANTIALIAS)
|
||||||
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
if str(default) == 'identicon':
|
if str(default) == 'identicon':
|
||||||
p = Pydenticon5()
|
p = Pydenticon5()
|
||||||
@@ -193,9 +201,11 @@ class AvatarImageView(TemplateView):
|
|||||||
data = BytesIO()
|
data = BytesIO()
|
||||||
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
img.save(data, 'PNG', quality=JPEG_QUALITY)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
if str(default) == 'mm' or str(default) == 'mp':
|
if str(default) == 'mm' or str(default) == 'mp':
|
||||||
# If mm is explicitly given, we need to catch that
|
# If mm is explicitly given, we need to catch that
|
||||||
@@ -231,9 +241,11 @@ class AvatarImageView(TemplateView):
|
|||||||
obj.save()
|
obj.save()
|
||||||
if imgformat == 'jpg':
|
if imgformat == 'jpg':
|
||||||
imgformat = 'jpeg'
|
imgformat = 'jpeg'
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/%s' % imgformat)
|
content_type='image/%s' % imgformat)
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
class GravatarProxyView(View):
|
class GravatarProxyView(View):
|
||||||
'''
|
'''
|
||||||
@@ -302,9 +314,11 @@ class GravatarProxyView(View):
|
|||||||
data = BytesIO(gravatarimagedata.read())
|
data = BytesIO(gravatarimagedata.read())
|
||||||
img = Image.open(data)
|
img = Image.open(data)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return HttpResponse(
|
response = HttpResponse(
|
||||||
data.read(),
|
data.read(),
|
||||||
content_type='image/%s' % file_format(img.format))
|
content_type='image/%s' % file_format(img.format))
|
||||||
|
response['Cache-Control'] = 'max-age=300'
|
||||||
|
return response
|
||||||
|
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
print('Value error: %s' % exc)
|
print('Value error: %s' % exc)
|
||||||
|
|||||||
Reference in New Issue
Block a user