fix double counting

This commit is contained in:
lelo 2025-03-24 11:40:44 +01:00
parent 81284fcc02
commit 7d938c046a

7
app.py
View File

@ -199,7 +199,8 @@ def serve_file(subpath):
# only log initial hits and not the reload of further file parts # only log initial hits and not the reload of further file parts
range_header = request.headers.get('Range') range_header = request.headers.get('Range')
# only request with starting from the beginning of the file will be tracked # only request with starting from the beginning of the file will be tracked
if request.method != 'HEAD' and (not range_header or range_header.startswith("bytes=0-")): # no range -> full file not just the first byte
if request.method == 'GET' and (not range_header or (range_header.startswith("bytes=0-") and range_header != "bytes=0-1")):
ip_address = request.remote_addr ip_address = request.remote_addr
user_agent = request.headers.get('User-Agent') user_agent = request.headers.get('User-Agent')
referrer = request.headers.get('Referer') referrer = request.headers.get('Referer')
@ -225,7 +226,7 @@ def serve_file(subpath):
img.save(img_bytes, format='PNG', quality=85) img.save(img_bytes, format='PNG', quality=85)
img_bytes = img_bytes.getvalue() img_bytes = img_bytes.getvalue()
cache.set(subpath, (img_bytes, mime)) cache.set(subpath, (img_bytes, mime))
response = send_file(io.BytesIO(img_bytes), mimetype=mime) response = send_file(io.BytesIO(img_bytes), mimetype=mime, conditional=True)
except Exception as e: except Exception as e:
app.logger.error(f"Image processing failed for {subpath}: {e}") app.logger.error(f"Image processing failed for {subpath}: {e}")
abort(500) abort(500)
@ -235,7 +236,7 @@ def serve_file(subpath):
with open(full_path, 'rb') as f: with open(full_path, 'rb') as f:
file_bytes = f.read() file_bytes = f.read()
cache.set(subpath, (file_bytes, mime)) cache.set(subpath, (file_bytes, mime))
response = send_file(io.BytesIO(file_bytes), mimetype=mime) response = send_file(io.BytesIO(file_bytes), mimetype=mime, conditional=True)
except Exception as e: except Exception as e:
app.logger.error(f"Failed to read file {subpath}: {e}") app.logger.error(f"Failed to read file {subpath}: {e}")
abort(500) abort(500)