ntfy webhook format

This commit is contained in:
Bel LaPointe
2025-04-22 20:40:19 -06:00
parent 54bbca8fea
commit 5b9bead96f
2 changed files with 27 additions and 10 deletions

18
main.go
View File

@@ -91,14 +91,24 @@ func Recursive(ctx context.Context) error {
cacheP := regexp.MustCompile(`[^a-zA-Z0-9]`).ReplaceAllString(p, `_`)
cacheP = path.Join(WebhookOnRecursiveMissCacheD, cacheP)
if _, err := os.Stat(cacheP); err != nil {
req, err := http.NewRequest(http.MethodPut, WebhookOnRecursiveMiss, strings.NewReader(p))
if err != nil {
panic(err)
}
u, err := url.Parse(WebhookOnRecursiveMiss)
if err != nil {
return fmt.Errorf("WebhookOnRecursiveMiss (%s) invalid: %w", WebhookOnRecursiveMiss, err)
}
q := u.Query()
q.Set("p", p)
u.RawQuery = q.Encode()
resp, err := http.Post(u.String(), "text/plain", strings.NewReader(p))
user := u.User
u.User = nil
if username := user.Username(); username != "" {
password, _ := user.Password()
req.SetBasicAuth(username, password)
}
req.URL = u
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to call %s for missing %s: %w", WebhookOnRecursiveMiss, p, err)
}