Add Unraid and Gotify notifications

This commit is contained in:
Mikei386
2026-06-14 13:50:02 +02:00
parent b7fe6ac86f
commit 1af23831f4
15 changed files with 232 additions and 44 deletions
+43
View File
@@ -3,6 +3,7 @@ package model
import (
"errors"
"fmt"
"net/url"
"path/filepath"
"regexp"
"strings"
@@ -42,12 +43,54 @@ func ValidateConfig(c Config) error {
}
repositoryOwners[job.RepositoryID] = job.ID
}
notifications := make(map[string]struct{}, len(c.Notifications))
for _, target := range c.Notifications {
if err := ValidateNotification(target); err != nil {
return fmt.Errorf("notification %q: %w", target.ID, err)
}
if _, exists := notifications[target.ID]; exists {
return fmt.Errorf("duplicate notification id %q", target.ID)
}
notifications[target.ID] = struct{}{}
}
if !filepath.IsAbs(c.Settings.RestoreRoot) {
return errors.New("restoreRoot must be absolute")
}
return nil
}
func ValidateNotification(target NotificationTarget) error {
if target.SchemaVersion != SchemaVersion || !idPattern.MatchString(target.ID) {
return errors.New("invalid schemaVersion or id")
}
if strings.TrimSpace(target.Name) == "" {
return errors.New("name is required")
}
switch target.Type {
case "unraid":
case "gotify":
parsed, err := url.Parse(target.URL)
if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {
return errors.New("Gotify URL must be an absolute HTTP or HTTPS URL")
}
if !idPattern.MatchString(target.TokenRef) {
return errors.New("Gotify tokenRef must be a valid secret ID")
}
default:
return fmt.Errorf("unsupported notification type %q", target.Type)
}
allowed := map[string]bool{"success": true, "warning": true, "failed": true}
if target.Enabled && len(target.Events) == 0 {
return errors.New("enabled notification requires at least one event")
}
for _, event := range target.Events {
if !allowed[event] {
return fmt.Errorf("unsupported event %q", event)
}
}
return nil
}
func ValidateJob(j Job) error {
if j.SchemaVersion != SchemaVersion || !idPattern.MatchString(j.ID) {
return errors.New("invalid schemaVersion or id")