feat(legacy): invalidate cached assets using md5sum (#2161)
* feat(legacy): invalidate cached assets using md5sum Don't rely on version to invalidate cached assets * use Assets::url() when loading legacy pages * fix script docs
This commit is contained in:
parent
1edcbc0657
commit
23578da4e2
24 changed files with 457 additions and 271 deletions
38
legacy/tools/assets-checksum-update.py
Executable file
38
legacy/tools/assets-checksum-update.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Extract the checksum for all the assets in the public directory.
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
legacy_root = Path(__file__).parent.parent
|
||||
|
||||
scan_dir = legacy_root / "public"
|
||||
dest_file = legacy_root / "application/assets.json"
|
||||
result = {}
|
||||
|
||||
|
||||
def compute_md5(filepath: Path) -> str:
|
||||
with filepath.open("rb") as file:
|
||||
buffer = hashlib.md5() # nosec
|
||||
while True:
|
||||
blob = file.read(8192)
|
||||
if not blob:
|
||||
break
|
||||
buffer.update(blob)
|
||||
|
||||
return buffer.hexdigest()
|
||||
|
||||
|
||||
def compute_md5_foreach_asset_in(root: Path):
|
||||
for path in root.iterdir():
|
||||
if path.is_dir():
|
||||
compute_md5_foreach_asset_in(path)
|
||||
else:
|
||||
if path.suffix in (".js", ".css"):
|
||||
result_key = str(path)[len(str(scan_dir)) + 1 :]
|
||||
result[result_key] = compute_md5(path)
|
||||
|
||||
|
||||
compute_md5_foreach_asset_in(scan_dir)
|
||||
dest_file.write_text(json.dumps(dict(sorted(result.items())), indent=2) + "\n")
|
Loading…
Add table
Add a link
Reference in a new issue