Support optional highlight names for uploaded photo batches

This commit is contained in:
2026-09-19 14:56:25 +03:30
parent 86dcfd71cb
commit f4037695a1
4 changed files with 65 additions and 9 deletions
+15 -3
View File
@@ -128,6 +128,9 @@ def create_app(data_dir=None, token=None):
caption = request.form.get("caption", "").strip()
if len(caption) > 4000:
abort(400, "Caption must be at most 4000 characters")
highlight = request.form.get("highlight", "").strip()
if len(highlight) > 200:
abort(400, "Highlight name must be at most 200 characters")
# Ordered byte hashes + caption make retries idempotent, even across restarts.
digest = hashlib.sha256(caption.encode())
temporary = Path(tempfile.mkdtemp(dir=data / "temporary"))
@@ -144,13 +147,22 @@ def create_app(data_dir=None, token=None):
Image.DecompressionBombError, Image.DecompressionBombWarning,
ImageCms.PyCMSError):
abort(400, f"Photo {index + 1} is unsupported, damaged, or exceeds 60 megapixels")
# Preserve existing IDs when omitted; named highlights participate in deduplication.
if highlight:
digest.update(b"\0highlight\0" + highlight.encode())
job = digest.hexdigest()
date = datetime.now(timezone.utc).isoformat()
manifest = {"id": job, "date": date, "caption": caption, "count": len(photos)}
manifest = {"id": job, "date": date, "caption": caption,
"highlight": highlight, "count": len(photos)}
atomic_json(temporary / "manifest.json", manifest)
content = ["---", "layout: post", f'title: "photo-{job}"',
f'date: "{date}"', "categories: art", "---", "",
f'<div id="photo-{job}"></div>', ""]
f'date: "{date}"', "categories: art"]
if highlight:
content.append(f"anchor: {json.dumps(highlight)}")
content.extend(["---", ""])
# The gallery already renders an anchor before the first photo for highlights.
if not highlight:
content.extend([f'<div id="photo-{job}"></div>', ""])
for index in range(len(photos)):
content.append(f'<p><img src="/img/arts/uploads/{job}/{index:02}.jpg" '
f'alt="{public_text(caption)}" loading="lazy"></p>')