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:
@@ -18,26 +18,43 @@ type Server struct {
|
||||
contentDir string
|
||||
outputDir string
|
||||
serve bool
|
||||
manage bool
|
||||
generator *Generator
|
||||
}
|
||||
|
||||
func NewServer(port, contentDir, outputDir string, serve bool, g *Generator) *Server {
|
||||
func NewServer(port, contentDir, outputDir string, serve, manage bool, g *Generator) *Server {
|
||||
return &Server{
|
||||
port: port,
|
||||
contentDir: contentDir,
|
||||
outputDir: outputDir,
|
||||
serve: serve,
|
||||
manage: manage,
|
||||
generator: g,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Listen() error {
|
||||
// routes builds the handler. The /manage pages are only registered with
|
||||
// -manage, so a service without the flag has no edit or delete code path at
|
||||
// all and answers 404 there.
|
||||
func (s *Server) routes() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /upload", s.handleUploadPage)
|
||||
mux.HandleFunc("POST /upload", s.handleUpload)
|
||||
if s.manage {
|
||||
mux.HandleFunc("GET /manage", s.handleManagePage)
|
||||
mux.HandleFunc("GET /manage/edit/{slug}", s.handleEditPage)
|
||||
mux.HandleFunc("POST /manage/edit/{slug}", s.handleEdit)
|
||||
mux.HandleFunc("GET /manage/delete/{slug}", s.handleDeletePage)
|
||||
mux.HandleFunc("POST /manage/delete/{slug}", s.handleDelete)
|
||||
}
|
||||
mux.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "ok")
|
||||
})
|
||||
return mux
|
||||
}
|
||||
|
||||
func (s *Server) Listen() error {
|
||||
mux := s.routes()
|
||||
|
||||
if s.serve {
|
||||
// Serve the generated site on the same port — for local development only.
|
||||
|
||||
Reference in New Issue
Block a user