Handle missing preview files with silent 404

This commit is contained in:
Leo Vasanko
2026-04-23 19:02:54 +00:00
parent 4626f1cdff
commit 7b3252c588
+8 -3
View File
@@ -97,7 +97,15 @@ async def preview(req, path):
quality = int(req.args.get("q", 60))
rel = PurePosixPath(sanitize(unquote(path)))
filepath = config.config.path / rel
if not filepath.is_file():
raise NotFound()
try:
stat = filepath.lstat()
except FileNotFoundError:
# File disappeared between existence check and stat.
raise NotFound() from None
etag = config.derived_secret(
"preview", rel, stat.st_mtime_ns, quality, maxsize, maxzoom
).hex()
@@ -112,9 +120,6 @@ async def preview(req, path):
logger.debug(f"Preview cache hit: {rel}")
return raw(cached.body, headers=cached.headers)
if not filepath.is_file():
raise NotFound("File not found")
# Generate preview
img = await asyncio.get_event_loop().run_in_executor(
req.app.ctx.threadexec, dispatch, filepath, quality, maxsize, maxzoom