diff --git a/.filecache/cache.db b/.filecache/cache.db deleted file mode 100644 index f887a38..0000000 Binary files a/.filecache/cache.db and /dev/null differ diff --git a/.filecache/cache.db-shm b/.filecache/cache.db-shm deleted file mode 100644 index fe9ac28..0000000 Binary files a/.filecache/cache.db-shm and /dev/null differ diff --git a/.filecache/cache.db-wal b/.filecache/cache.db-wal deleted file mode 100644 index e69de29..0000000 diff --git a/app.py b/app.py index 683c7a5..861a5bf 100755 --- a/app.py +++ b/app.py @@ -13,6 +13,7 @@ app = Flask(__name__) # Use a raw string for the UNC path. app.config['MP3_ROOT'] = r'/mp3_root' +# app.config['MP3_ROOT'] = r'\\192.168.10.10\docker2\sync-bethaus\syncfiles\folders' app.config['SECRET_KEY'] = os.urandom(24) app.config['ALLOWED_SECRETS'] = { 'test': datetime(2026, 3, 31, 23, 59, 59), @@ -177,6 +178,7 @@ def serve_file(filename): full_path = os.path.normpath(os.path.join(app.config['MP3_ROOT'], decoded_filename)) if not os.path.isfile(full_path): + app.logger.error(f"File not found: {full_path}") return "File not found", 404 mime, _ = mimetypes.guess_type(full_path) @@ -187,12 +189,14 @@ def serve_file(filename): # Check cache first (using diskcache) cached = cache.get(filename) if cached: + app.logger.info(f"Cache hit for {filename}") cached_file_bytes, mime = cached cached_file = io.BytesIO(cached_file_bytes) response = send_file(cached_file, mimetype=mime) else: + app.logger.info(f"Cache miss for {filename}") if mime and mime.startswith('image/'): - # Image processing + # Image processing branch (with caching) try: with Image.open(full_path) as img: img.thumbnail((1200, 1200)) @@ -202,16 +206,24 @@ def serve_file(filename): cache.set(filename, (img_bytes, mime)) response = send_file(io.BytesIO(img_bytes), mimetype=mime) except Exception as e: - app.logger.error(f"Image processing failed: {e}") + app.logger.error(f"Image processing failed for {filename}: {e}") abort(500) else: - # Other file types - response = send_file(full_path, mimetype=mime) + # Cache non-image files: read bytes and cache + try: + with open(full_path, 'rb') as f: + file_bytes = f.read() + cache.set(filename, (file_bytes, mime)) + response = send_file(io.BytesIO(file_bytes), mimetype=mime) + except Exception as e: + app.logger.error(f"Failed to read file {filename}: {e}") + abort(500) # Set Cache-Control header (browser caching for 1 day) - response.headers['Cache-Control'] = 'public, max-age=86400' # 1 day + response.headers['Cache-Control'] = 'public, max-age=86400' return response + @app.route("/transcript/") @require_secret def get_transcript(filename):