fix: mtime index dans processed_full, print 404, galerie full-width
This commit is contained in:
@@ -22,20 +22,49 @@ def _get_id(item: dict) -> str:
|
||||
|
||||
|
||||
def _find_file(media_dir: str, photo_id: str) -> Path | None:
|
||||
"""Cherche un fichier image correspondant à l'identifiant dans le répertoire media."""
|
||||
"""Cherche un fichier image correspondant à l'identifiant.
|
||||
|
||||
Cherche dans media_dir, processed_full/ et les chemins photobooth standard.
|
||||
"""
|
||||
base = Path(media_dir)
|
||||
if not base.exists():
|
||||
return None
|
||||
for ext in (".jpg", ".jpeg", ".png"):
|
||||
f = base / f"{photo_id}{ext}"
|
||||
if f.exists():
|
||||
return f
|
||||
matches = list(base.rglob(f"{photo_id}{ext}"))
|
||||
if matches:
|
||||
return matches[0]
|
||||
candidates = [
|
||||
base,
|
||||
base / "processed_full",
|
||||
Path("/home/pi/photobooth-data/media/processed_full"),
|
||||
Path("/home/pi/photobooth-data/media"),
|
||||
]
|
||||
for d in candidates:
|
||||
if not d.exists():
|
||||
continue
|
||||
for ext in (".jpg", ".jpeg", ".png"):
|
||||
f = d / f"{photo_id}{ext}"
|
||||
if f.exists():
|
||||
return f
|
||||
return None
|
||||
|
||||
|
||||
def _build_mtime_index(media_dir: Path) -> dict[str, float]:
|
||||
"""Construit un index {stem: mtime, name: mtime} en cherchant dans les dossiers connus."""
|
||||
index: dict[str, float] = {}
|
||||
checked: set[Path] = set()
|
||||
candidates = [
|
||||
media_dir,
|
||||
media_dir / "processed_full",
|
||||
Path("/home/pi/photobooth-data/media/processed_full"),
|
||||
Path("/home/pi/photobooth-data/media"),
|
||||
]
|
||||
for d in candidates:
|
||||
if not d.exists() or d in checked:
|
||||
continue
|
||||
checked.add(d)
|
||||
for f in d.iterdir():
|
||||
if f.is_file() and f.suffix.lower() in (".jpg", ".jpeg", ".png"):
|
||||
mt = f.stat().st_mtime
|
||||
index[f.name] = mt
|
||||
index[f.stem] = mt
|
||||
return index
|
||||
|
||||
|
||||
def _require_auth(request: Request):
|
||||
return request.session.get("authenticated") is True
|
||||
|
||||
@@ -66,20 +95,7 @@ async def admin_get_photos(
|
||||
photos = [p for p in all_photos if _is_image(p)]
|
||||
|
||||
# Enrichit chaque photo avec mtime depuis le disque
|
||||
# Indexe par stem ET par nom complet pour couvrir les deux formats d'id
|
||||
mtime_index: dict[str, float] = {}
|
||||
for media_dir_candidate in [
|
||||
media_dir,
|
||||
Path("/home/pi/photobooth-data/media/processed_full"),
|
||||
Path("/home/pi/photobooth-data/media"),
|
||||
]:
|
||||
if media_dir_candidate.exists():
|
||||
for f in media_dir_candidate.iterdir():
|
||||
if f.is_file():
|
||||
mt = f.stat().st_mtime
|
||||
mtime_index[f.name] = mt # uuid.jpg
|
||||
mtime_index[f.stem] = mt # uuid
|
||||
break
|
||||
mtime_index = _build_mtime_index(media_dir)
|
||||
|
||||
for p in photos:
|
||||
pid = _get_id(p)
|
||||
|
||||
Reference in New Issue
Block a user