From 270ad50cf552ad658cfc98608615b4c381e2af23 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 1 May 2026 23:10:35 -0500 Subject: [PATCH] Set Cache-Control on static files with a version tag --- app.py | 2 +- src/copyvios/__init__.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 197598a..0cac91c 100755 --- a/app.py +++ b/app.py @@ -86,7 +86,7 @@ def write_access_log(response: Response) -> Response: @functools.lru_cache def _get_hash(path: str, mtime: float) -> str: - # mtime is used as part of the cache key + del mtime # mtime is used as part of the cache key with open(path, "rb") as fp: return hashlib.sha1(fp.read()).hexdigest() diff --git a/src/copyvios/__init__.py b/src/copyvios/__init__.py index 059861c..1530e91 100644 --- a/src/copyvios/__init__.py +++ b/src/copyvios/__init__.py @@ -3,9 +3,17 @@ import logging import os from logging.handlers import TimedRotatingFileHandler -from flask import Flask +from flask import Flask, request -app = Flask( + +class CopyviosFlask(Flask): + def get_send_file_max_age(self, filename: str | None) -> int | None: + if request.args.get("v"): + return 365 * 24 * 60 * 60 + return super().get_send_file_max_age(filename) + + +app = CopyviosFlask( "copyvios", instance_path=os.getcwd(), instance_relative_config=True,