Files
decypharr/pkg/server/webhook.go
2025-04-13 11:29:08 +01:00

55 lines
1.4 KiB
Go

package server
import (
"cmp"
"github.com/goccy/go-json"
"github.com/sirrobot01/decypharr/pkg/service"
"net/http"
)
func (s *Server) handleTautulli(w http.ResponseWriter, r *http.Request) {
// Verify it's a POST request
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
// Parse the JSON body from Tautulli
var payload struct {
Type string `json:"type"`
TvdbID string `json:"tvdb_id"`
TmdbID string `json:"tmdb_id"`
Topic string `json:"topic"`
AutoProcess bool `json:"autoProcess"`
}
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
s.logger.Error().Err(err).Msg("Failed to parse webhook body")
http.Error(w, "Failed to parse webhook body: "+err.Error(), http.StatusBadRequest)
return
}
if payload.Topic != "tautulli" {
http.Error(w, "Invalid topic", http.StatusBadRequest)
return
}
if payload.TmdbID == "" && payload.TvdbID == "" {
http.Error(w, "Invalid ID", http.StatusBadRequest)
return
}
svc := service.GetService()
repair := svc.Repair
mediaId := cmp.Or(payload.TmdbID, payload.TvdbID)
if repair == nil {
http.Error(w, "Repair service is not enabled", http.StatusInternalServerError)
return
}
if err := repair.AddJob([]string{}, []string{mediaId}, payload.AutoProcess, false); err != nil {
http.Error(w, "Failed to add job: "+err.Error(), http.StatusInternalServerError)
return
}
}