Settings → Notifications sends a message to Discord, Pushover, ntfy, Gotify or a JSON webhook when a scan finds songs that newly need review, when auto-link replaced identical files, and when an automatic cleanup ran. Each event can be turned off and each service tested; an optional Playlink address adds a link back to the right page. A new per-pair option removes empty slave folders after each scan. Only folders with no file at all inside are removed (into the quarantine, recorded in History); folders holding any file wait in Cleanup, folders changed within the settle time are skipped, and dry run removes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/cdnutter/playlink/internal/notify"
|
|
)
|
|
|
|
func (s *Server) notifyRoutes(r chi.Router) {
|
|
r.Get("/notifications", s.handleGetNotify)
|
|
r.Put("/notifications", s.handlePutNotify)
|
|
r.Post("/notifications/test", s.handleTestNotify)
|
|
}
|
|
|
|
func (s *Server) handleGetNotify(w http.ResponseWriter, r *http.Request) {
|
|
writeJSON(w, 200, s.cfg.Notifier.Config(r.Context()))
|
|
}
|
|
|
|
func (s *Server) handlePutNotify(w http.ResponseWriter, r *http.Request) {
|
|
var c notify.Config
|
|
if !readJSON(w, r, &c) {
|
|
return
|
|
}
|
|
if err := s.cfg.Notifier.SetConfig(r.Context(), c); err != nil {
|
|
writeErr(w, 400, err)
|
|
return
|
|
}
|
|
writeJSON(w, 200, s.cfg.Notifier.Config(r.Context()))
|
|
}
|
|
|
|
// handleTestNotify sends a test message to a target as entered, saved or not.
|
|
func (s *Server) handleTestNotify(w http.ResponseWriter, r *http.Request) {
|
|
var body struct {
|
|
Target notify.Target `json:"target"`
|
|
BaseURL string `json:"base_url"`
|
|
}
|
|
if !readJSON(w, r, &body) {
|
|
return
|
|
}
|
|
if err := s.cfg.Notifier.Test(r.Context(), body.Target, body.BaseURL); err != nil {
|
|
writeErr(w, 400, err)
|
|
return
|
|
}
|
|
writeJSON(w, 200, map[string]bool{"ok": true})
|
|
}
|