From 7d938c046ad8e3c8c284da47453805395843a198 Mon Sep 17 00:00:00 2001 From: lelo Date: Mon, 24 Mar 2025 11:40:44 +0100 Subject: [PATCH] fix double counting --- app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index f7fba05..1c31272 100755 --- a/app.py +++ b/app.py @@ -199,7 +199,8 @@ def serve_file(subpath): # only log initial hits and not the reload of further file parts range_header = request.headers.get('Range') # 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 user_agent = request.headers.get('User-Agent') referrer = request.headers.get('Referer') @@ -225,7 +226,7 @@ def serve_file(subpath): img.save(img_bytes, format='PNG', quality=85) img_bytes = img_bytes.getvalue() 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: app.logger.error(f"Image processing failed for {subpath}: {e}") abort(500) @@ -235,7 +236,7 @@ def serve_file(subpath): with open(full_path, 'rb') as f: file_bytes = f.read() 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: app.logger.error(f"Failed to read file {subpath}: {e}") abort(500)