feat(manage): add /manage pages to edit and delete photos, behind -manage

/manage lists every photo; /manage/edit/{slug} rewrites the photo's
.toml sidecar (caption, date), /manage/delete/{slug} asks for
confirmation and then removes the image, its sidecar and everything
generated from them. Builds now drop day pages of days without photos
and pager pages past the last one, so a delete or a date change leaves
nothing behind.

The pages are off by default: the routes are only registered with
-manage, so an install that does not opt in has no such code path and
answers 404. NixOS gets services.photogallery.manage.enable, which
also adds the nginx location only when on. Like /upload, the pages
carry no auth of their own and are not linked from the public site.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
fox
2026-09-30 08:17:17 +02:00
co-authored by Claude Fable 5.1
parent f1abd45f24
commit 3f719359de
12 changed files with 1108 additions and 21 deletions
+33
View File
@@ -130,3 +130,36 @@ func TestSwitchingDefaultViewDropsOldViewDir(t *testing.T) {
t.Errorf("site root is still the timeline")
}
}
func TestShrinkingSiteDropsLeftoverPages(t *testing.T) {
output := t.TempDir()
buildSite(t, output, viewTimeline) // three photos, page size two
content := t.TempDir()
var img bytes.Buffer
if err := jpeg.Encode(&img, image.NewRGBA(image.Rect(0, 0, 8, 8)), nil); err != nil {
t.Fatal(err)
}
writeFile(t, filepath.Join(content, "one.jpg"), img.Bytes())
writeFile(t, filepath.Join(content, "one.toml"),
[]byte("caption = \"one\"\ndate = \"2026-06-14\"\n"))
// The same output directory, now fed a single photo: one page per view,
// one day.
g := NewGenerator(content, output, "https://photos.example.com",
"Ada", "", "", "", "", "Crimson Pro", "Manjari", 2, viewTimeline)
if err := g.Build(); err != nil {
t.Fatal(err)
}
for _, gone := range []string{"page/2", "grid/page/2", "day/2026-06-10"} {
if _, err := os.Stat(filepath.Join(output, filepath.FromSlash(gone))); !os.IsNotExist(err) {
t.Errorf("leftover %s survived", gone)
}
}
for _, kept := range []string{"index.html", "grid/index.html", "day/2026-06-14/index.html"} {
if _, err := os.Stat(filepath.Join(output, filepath.FromSlash(kept))); err != nil {
t.Errorf("%s is missing: %v", kept, err)
}
}
}