fix double counting
This commit is contained in:
parent
81284fcc02
commit
7d938c046a
7
app.py
7
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user