diff --git a/analytics.py b/analytics.py index 6c2a468..65e78d7 100644 --- a/analytics.py +++ b/analytics.py @@ -71,6 +71,7 @@ def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, VALUES (?, ?, ?, ?, ?, ?, ?, ?) ''', (iso_ts, rel_path, filesize, mime, ip_address, user_agent, device_id, cached)) file_access_temp.insert(0, [iso_ts, rel_path, filesize, mime, ip_address, user_agent, device_id, cached]) + print("Log: ", iso_ts, rel_path, filesize, mime, ip_address, user_agent, device_id, cached) return iso_ts diff --git a/app.py b/app.py index 113ba50..7ad9749 100755 --- a/app.py +++ b/app.py @@ -224,11 +224,14 @@ def serve_file(subpath): cache = cache_other # Check if the file is already cached + + was_cached = None cached = cache.get(subpath) if cached: cached_file_bytes, mime = cached cached_file = io.BytesIO(cached_file_bytes) filesize = len(cached_file.getbuffer()) + was_cached = True response = send_file(cached_file, mimetype=mime) else: if mime and mime.startswith('image/'): @@ -247,6 +250,7 @@ def serve_file(subpath): img.save(img_bytes_io, format=output_format, **save_kwargs) thumb_bytes = img_bytes_io.getvalue() cache.set(subpath, (thumb_bytes, output_mime)) + was_cached = False response = send_file(io.BytesIO(thumb_bytes), mimetype=output_mime, conditional=True) except Exception as e: app.logger.error(f"Image processing failed for {subpath}: {e}") @@ -259,6 +263,7 @@ def serve_file(subpath): cache.set(subpath, (file_bytes, mime)) file_bytes_io = io.BytesIO(file_bytes) filesize = len(file_bytes_io.getbuffer()) + was_cached = False response = send_file(file_bytes_io, mimetype=mime, conditional=True) except Exception as e: app.logger.error(f"Failed to read file {subpath}: {e}") @@ -278,7 +283,7 @@ def serve_file(subpath): logging = True if logging: - a.log_file_access(subpath, filesize, mime, ip_address, user_agent, session['device_id'], bool(cached)) + a.log_file_access(subpath, filesize, mime, ip_address, user_agent, session['device_id'], was_cached) return response