feat: proper thumbnail cache handling, removal of cachebusters

This commit is contained in:
s3lph 2024-12-11 01:31:29 +01:00
parent 5a0c0cf148
commit d163cfda05
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
7 changed files with 10 additions and 9 deletions

View file

@ -67,8 +67,9 @@ def get_thumbnail(resource: str, filename: str):
static: str = os.path.abspath(config['staticroot'])
rpath: str = os.path.join(static, 'upload/thumbnails', resource)
resp = bottle.static_file(filename, root=rpath)
if resp.status_code != 200:
if resp.status_code >= 400:
resp = bottle.static_file('default.png', root=rpath)
resp.headers['Cache-Control'] = 'public, max-age=0;'
return resp

View file

@ -112,7 +112,7 @@
<td>{{ product.price_non_member | chf }}</td>
<td>{{ '✓' if product.custom_price else '✗' }}</td>
<td>{{ '✓' if product.stockable else '✗' }}</td>
<td><img style="height: 2em;" src="/static/upload/thumbnails/products/{{ product.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ product.name }}" draggable="false"></td>
<td><img style="height: 2em;" src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" draggable="false"></td>
<td>
<div class="btn-group" role="group">
<a class="btn btn-primary" href="/modproduct?productid={{ product.id }}">Edit</a>
@ -134,7 +134,7 @@
<div class="col-sm-2 g-4">
<div class="card h-100">
<img class="card-img-top" src="/static/upload/thumbnails/users/default.png?cacheBuster={{ now }}" alt="Default user avatar" />
<img class="card-img-top" src="/static/upload/thumbnails/users/default.png" alt="Default user avatar" />
<div class="card-body">
<label class="card-title" for="admin-default-images-user">Default user avatar</label>
<div class="card-text">
@ -146,7 +146,7 @@
<div class="col-sm-2 g-4">
<div class="card h-100">
<img class="card-img-top" src="/static/upload/thumbnails/products/default.png?cacheBuster={{ now }}" alt="Default product image" />
<img class="card-img-top" src="/static/upload/thumbnails/products/default.png" alt="Default product image" />
<div class="card-body">
<label class="card-title" for="admin-default-images-product">Default product image</label>
<div class="card-text">

View file

@ -36,7 +36,7 @@
<input class="form-control" id="modproduct-balance" name="stock" type="text" value="{{ product.stock }}" /><br/>
<label class="form-label" for="modproduct-image">
<img height="150" src="/static/upload/thumbnails/products/{{ product.id }}.png?cacheBuster={{ now }}" alt="Image of {{ product.name }}" />
<img height="150" src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Image of {{ product.name }}" />
</label><br/>
<input class="form-control" id="modproduct-image" type="file" name="image" accept="image/*" /><br/>

View file

@ -49,7 +49,7 @@
<input class="form-control" id="moduser-account-balance-reason" type="text" name="reason" placeholder="Shows up on receipt" /><br/>
<label class="form-label" for="moduser-account-avatar">
<img height="150" src="/static/upload/thumbnails/users/{{ user.id }}.png?cacheBuster={{ now }}" alt="Avatar of {{ user.name }}" />
<img height="150" src="/static/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
</label><br/>
<input class="form-control" id="moduser-account-avatar" type="file" name="avatar" accept="image/*" /><br/>

View file

@ -66,7 +66,7 @@
</span>
{% endif %}
</div>
<img class="card-img-bottom" src="/static/upload/thumbnails/products/{{ product.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ product.name }}" draggable="false"/>
<img class="card-img-bottom" src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" draggable="false"/>
{% set pstock = stock.get_stock(product) %}
{% if pstock is not none %}
<div class="card-img-overlay d-flex flex-column justify-content-end">

View file

@ -28,7 +28,7 @@
<div class="col-xl-1 col-md-2 col-sm-3 col-4 mb-3">
<div class="card text-bg-light">
<div class="card-header">{{ authuser.name }}</div>
<img class="card-img-bottom" draggable="false" src="/static/upload/thumbnails/users/{{ authuser.id }}.png?cacheBuster={{ now }}" alt="Avatar of {{ authuser.name }}">
<img class="card-img-bottom" draggable="false" src="/static/upload/thumbnails/users/{{ authuser.id }}.png" alt="Avatar of {{ authuser.name }}">
</div>
</div>
</div>

View file

@ -10,7 +10,7 @@
<div class="card-header">
{{ user.name }}
</div>
<img class="card-img-bottom" src="/static/upload/thumbnails/users/{{ user.id }}.png?cacheBuster={{ now }}" alt="Avatar of {{ user.name }}" draggable="false"/>
<img class="card-img-bottom" src="/static/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" draggable="false"/>
</a>
</div>
{% endfor %}