surge refill
This commit is contained in:
+8
-11
@@ -16,11 +16,9 @@ from .config import (
|
||||
SOCKETIO_CORS_ALLOWED_ORIGINS,
|
||||
)
|
||||
from .db import init_db
|
||||
from .services.frontend_assets import asset_path, bootstrap_css_path, validate_offline_assets
|
||||
from .utils import file_md5
|
||||
from .services.frontend_assets import asset_path, bootstrap_css_path, static_hash, validate_offline_assets
|
||||
|
||||
socketio = SocketIO(cors_allowed_origins=SOCKETIO_CORS_ALLOWED_ORIGINS, ping_timeout=30, async_mode="threading")
|
||||
_static_md5_cache: dict[tuple, str] = {}
|
||||
|
||||
|
||||
def _wants_json_response() -> bool:
|
||||
@@ -78,17 +76,15 @@ def create_app() -> Flask:
|
||||
|
||||
@app.context_processor
|
||||
def static_helpers():
|
||||
def current_static_hash() -> str:
|
||||
return static_hash(Path(app.static_folder or ""))
|
||||
|
||||
def static_url(filename: str) -> str:
|
||||
path = Path(app.static_folder or "") / filename
|
||||
try:
|
||||
stat = path.stat()
|
||||
key = (filename, stat.st_mtime_ns, stat.st_size)
|
||||
version = _static_md5_cache.get(key)
|
||||
if not version:
|
||||
_static_md5_cache.clear()
|
||||
version = file_md5(path)
|
||||
_static_md5_cache[key] = version
|
||||
return url_for("static", filename=filename, v=version)
|
||||
path.stat()
|
||||
# Note: A single static hash keeps module imports, CSS and local libraries on the same cache version.
|
||||
return url_for("static", filename=filename, v=current_static_hash())
|
||||
except OSError:
|
||||
return url_for("static", filename=filename)
|
||||
|
||||
@@ -104,6 +100,7 @@ def create_app() -> Flask:
|
||||
"static_url": static_url,
|
||||
"frontend_asset_url": frontend_asset_url,
|
||||
"bootstrap_theme_url": bootstrap_theme_url,
|
||||
"static_hash": current_static_hash,
|
||||
}
|
||||
|
||||
@app.after_request
|
||||
|
||||
Reference in New Issue
Block a user